Solved

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

Posted on 2004-04-22
7
1,332 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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.

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now