Forum Moderators: coopster

Message Too Old, No Replies

Difference between 301 header report from apache to PHP

         

bouncybunny

6:37 am on Apr 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi

I have just implemented the following PHP 301 redirect on a Windows server.

<?php
// Permanent redirection
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.example.com");
exit();
?>

I checked this on one of those online server header checkers and it appears to be showing a correct 301 redirect message. I think...

HTTP Status Code: HTTP/1.1 301 OK

However, the status is slightly different to when I apply 301 redirect code to an .htaccess file on a Linux/Apache server.

HTTP Status Code: HTTP/1.1 301 Moved Permanently

What is the difference between the "301 OK" message and the "301 Moved Permanently" message? In both cases the redirect appears to work properly. I.E. the user/browser/spider is being sent to the new page.

I just want to be sure that search engines are being sent a correct 301 redirect.

Thanks for any help.

[edited by: dreamcatcher at 9:45 am (utc) on April 17, 2007]
[edit reason] Use example.com, thanks. [/edit]

oziman

7:24 am on Apr 17, 2007 (gmt 0)

10+ Year Member



bouncybunny -

They're both doing the same thing and returning the same status codes. 301 OK and 301 Moved Permanently are both fine.

Just seems like PHP and Apache have slightly different ways of returning the codes.

bouncybunny

7:56 am on Apr 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Many thanks. :)

cameraman

10:29 am on Apr 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just for curiosity's sake you might try this:
header("HTTP/1.1 301 Moved Permanently",true,301);

bouncybunny

1:27 pm on Apr 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That seems to not even throw a 301. Just a 200 found.

coopster

3:54 pm on Apr 17, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



The "message" part is called the "Reason Phrase"


6.1.1 Status Code and Reason Phrase

The Status-Code element is a 3-digit integer result code of the 
attempt to understand and satisfy the request. These codes are fully
defined in section 10. The Reason-Phrase is intended to give a short
textual description of the Status-Code. The Status-Code is intended
for use by automata and the Reason-Phrase is intended for the human
user. The client is not required to examine or display the Reason-
Phrase.

Resource: RFC2616

cameraman

6:24 pm on Apr 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That seems to not even throw a 301. Just a 200 found.

That's weird, that's what I use. I've not examined the resulting headers with a utility, but I've seen it at work in the server log.

bouncybunny

9:10 pm on Apr 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks Coopster. So search engine bots aren't interested in the 'Reason-Phrase'?

cameraman

Just to confirm. This is what I tested out in full. Is this what you meant?

<?php
// Permanent redirection
header("HTTP/1.1 301 Moved Permanently",true,301);
header("Location: http://www.example.com");
exit();
?>

cameraman

10:02 pm on Apr 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yep, that's it.
I have three domains going to a single web space. Personally I want to know by which domain name visitors arrived, so using an .htaccess rewrite to make google happy wouldn't have made me happy. I already had a script that was at the top of every page, so I added a check to see if it's google; if it is and they're not there by the 'main' domain name, I redirect them.
I watch my 'latest visitors' log pretty regularly, and saw google being redirected several times until they stopped coming in that way.