Solved

Redirects NOT Working for Internet Explorer --- header("Location:http://dmglobal.net".$_GETENV["REQUEST_URI"]); ---

Posted on 2004-04-22
7
1,336 Views
Last Modified: 2013-12-12
What I am trying to do can be explained by the following webpage:
http://forums.hostmatters.com/showthread.php?t=11025&goto=nextoldest

My problem is that the the redirects are not working for Internet Explorer.  They work great on Netscape or Opera but not Internet Explorer.

My Code for Redirecting:
<?php

function redirection($url){
 if (headers_sent()){
   print('<meta http-equiv="refresh" content="0;URL='.$url.'">');
     } else {
       header("Location: $url\n");
        }
        }
echo "You will now be redirected to dmglobal.net";
redirection("http://dmglobal.net".$_GETENV["REQUEST_URI"]);

?>

Also I don't know if it is significant but I am using www.OneAndOne.com to do my webhosting.

How do I get the redirects to work on Internet Explorer?
0
Comment
Question by:razorwire
  • 3
  • 2
  • 2
7 Comments
 
LVL 6

Expert Comment

by:jkna_gunn
ID: 10897147
i copied your code and it ran fine for me.
what version of IE are you using?
0
 

Author Comment

by:razorwire
ID: 10900159
I am using Internet Explorer 6.

The code works find for me if I go directly to the php page with the code.  However, there are additional parts to this.  Let me be more specific:

URL1:
http://redirectsite.com/.htaccess
Code:
ErrorDocument 404 /include/404.php

URL2:
http://redirectsite.com/include/404.php
Code:
<?php
function redirection($url){
 if (headers_sent()){
   print('<meta http-equiv="refresh" content="0;URL='.$url.'">');
     } else {
       header("Location: $url\n");
        }
        }
echo "You will now be redirected to dmglobal.net";
redirection("http://dmglobal.net".$_GETENV["REQUEST_URI"]);
?>

URL3:
http://redirectsite.com/ThisPageIsNonExisitant

- URL2 works in Internet Explorer, Opera, Netscape, etc.

- URL3 is a Non-Existant webpage, so you should get the 404 file not found error, except that the .htaccess file has been specified to redirect you on this error.  In the case of Opera or Netscape you are redirected.  However, you are NOT redirected with Internet Explorer.

One thing I think I noticed too is if I remove the line:
echo "You will now be redirected to dmglobal.net";
URL3 will not work on any browsers.
0
 
LVL 6

Expert Comment

by:jkna_gunn
ID: 10900423
i guess because the echo is forcing the page to send the headers.
maybe you should set all the headers yourself manually.
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 15

Accepted Solution

by:
JakobA earned 250 total points
ID: 10914278
I seems to remember that in some recent recent IE versions 404 pages are ignored if they are 'too short' and instead IE's default 404 page is inserted.
Try padding the file with a lot of useless text and see if that helps.
0
 

Author Comment

by:razorwire
ID: 10920343
I have not had success yet but I wanted to gather some notes here:

From: http://www.htmlhelp.com/faq/html/publish.html#ignored-msg

4.14. Why is my custom 404 message not displayed?
If no browser displays your custom 404 messages, then your server probably is not configured properly.

If only Internet Explorer ignores your custom 404 messages, then you've been caught by its "friendly" HTTP error messages. When a special HTTP response (e.g., a 404 response) is shorter than 512 bytes, Internet Explorer substitutes its own message for the one delivered by the server. As a user of Internet Explorer, you can disable this feature in the "Advanced" options panel. As a web author, your only recourse is to make the error page longer.

http://us3.php.net/header

Michail A.Baikov
18-Jan-2003 09:20
For correct work with IE (without Page not found Error):

header("HTTP/1.0 301 Moved Permanently");
header("Location: ".$url);

change to:

header("HTTP/1.1 301 Moved Permanently");
header("Location: ".$url);
header("Connection: close");
0
 

Author Comment

by:razorwire
ID: 10952699
One thing I messed up on was I added a bunch of ######################## to my php file to make it over 512 bytes.  However, I don't think the ##### get counted for the byte size when the page is sent in php.  I fixed this by making an echo ".............................  ... ......................................."; statement in my php file to push the file size over 512 bytes.  The redirects now work as desired in IE, Netscape, etc..
0
 
LVL 15

Expert Comment

by:JakobA
ID: 10954812
Oops, yws i should have pointed that out. It is the file sent to the briowser that counts, not the php file generating it :-))
Thanks for the points.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question