Forum Moderators: coopster

Message Too Old, No Replies

hybrid 301/404/refresh & Internet Explorer trouble

IE does not allow any output after header status code

         

deverson

1:05 am on Jun 4, 2005 (gmt 0)

10+ Year Member



A client of mine needed a SEO friendly 301 redirect from their old site to a new one. However, it was imperative that a message be shown telling all users of the site switch. In short, I needed to kill 4 birds with one stone;

1) Set my 301 as the default 404 page
2) Send a 301 status header
3) Display message
4) redirect to the new page

Of course JavaScript refreshes and meta refreshes where out of the question because they are not SEO friendly. The simple header 301 status & header redirect option was out because it redirects before any message can be shown. So I was in luck when I discovered the handy php header refresh function. After this discovery, it took only a minute to code this:

//set header
header("HTTP/1.1 301 Moved Permanently");

//perform url refresh in 3 seconds
header( 'refresh: 3; url=http://www.example.com' );

//print temp message here
echo '<html>.........';

It seemed to be a simple solution, and worked perfectly in firefox; catching all 404 errors, giving the right 301 header, displaying the custom message and redirecting.
To my dismay, I found that this solution doesnt work for IE. In fact, its seems IE doesnt work if you attempt to display output after this header status code.
I could probably code a clunky workaround for this task, but I'd rather have the elegant solution that I got with this code in Firefox. Is this a known bug? Did I overlook something? Is there any even simpler solution?
Please help
Thanks!

enotalone

12:56 am on Jun 6, 2005 (gmt 0)

10+ Year Member



after you give the 301 header you could use the same header function to redirect.

header("Location: http://www.example.com/");

this will not work?
on php.net they do mention that there is some IE bug with header function and someone gave a solution.

encyclo

1:08 am on Jun 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I feel that IE is actually handling this better than Firefox (which makes a change). There cannot be any content after a 301 redirect: that code means that the page has been moved elsewhere, so if you print a message then the page still exists - which negates the 301. The question is not just how IE handles it, either - you are surely doing this for the benefit of the search engines, and the confusing headers may mean that the redirect might not work correctly for them either.

In this situation, my first thought would be to use some form of cloaking (even if it is just simple user agent detection for Googlebot, Slurp and MSNBot) to issue a standard 301 redirect to the bots and a meta refresh with expanation to everyone else. Either that, or convince your client that the silent 301 is the better solution for all.

deverson

4:10 pm on Jun 6, 2005 (gmt 0)

10+ Year Member



Thanks for all your help.
My work around is to have give a 301 header & a redirect to a page with a header refresh i.e.

//404 file
header('HTTP/1.1 301');
header("Location: http://example.com/refresh.php);

then

//refresh.php
header( "refresh: 3; url=http://example2.com" );
echo '<html> ....';

this works fine, but is this Search Engine friendly? would I get the pageRank to propagate through to e.g. example2.com.

Thanks