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

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?
razorwireAsked:
Who is Participating?
 
JakobAConnect With a Mentor Commented:
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
 
jkna_gunnCommented:
i copied your code and it ran fine for me.
what version of IE are you using?
0
 
razorwireAuthor Commented:
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
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
jkna_gunnCommented:
i guess because the echo is forcing the page to send the headers.
maybe you should set all the headers yourself manually.
0
 
razorwireAuthor Commented:
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
 
razorwireAuthor Commented:
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
 
JakobACommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.