Solved

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

Posted on 2004-04-22
7
1,330 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Responsive Design Tools 6 41
Jquery Autocomplete PHP script 3 24
wordpress url rewriting plugin 5 11
regex expression 9 23
Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

744 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

11 Experts available now in Live!

Get 1:1 Help Now