Forum Moderators: coopster

Message Too Old, No Replies

header() question

         

omax

1:56 pm on Dec 28, 2007 (gmt 0)

10+ Year Member



Hello

I removed some pages from a site
and I have some php code like
if (url is to a page that has been removed)
{
header("HTTP/1.1 410 Gone");
header("Location: [....");...]
exit();
}

But when I look on the logs I see that when google tries to access the page it gets http code: 302 instead of 410.
I'm doing something wrong?

Thank you.

jatar_k

2:43 pm on Dec 28, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



why send the location header?

why not just the 410?

PHP_Chimp

5:53 pm on Dec 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The header('Location: ...') sends a 302 response (as it says in the manual). So when google are getting you page they get the 410...but also get a 302...so they must be very confused.

If you want to have a standard error page then you could look at using .htaccess and the ErrorDocument410 to send people to a page that you have made saying that 'This site has been updated bla bla bla'.

You may also note that 410 header is an HTTP1.1 response. There are still a few browsers that dont support 1.1, so you would be better using HTTP/1.0 404 (although I agree with you that when pages are gone a 410 is a better response...however there are also some search engines that dont support HTTP/1.1 either).

If you are really keen (and I take it that you must be...as a lot of people dont seem to bother with 410 at all) you could examine the $_SERVER['SERVER_PROTOCOL'] [php.net], as this should give you the protocol that was used for the request. If this is 1.0 then you would return a 404 header, if this is 1.1 you would return your 410 header.

However you would be better off doing this at the server level (.htaccess) as opposed to the php level.
This may well be why so many people dont bother with 410 headings ;)

omax

4:52 pm on Dec 30, 2007 (gmt 0)

10+ Year Member



Hello

Thank you very much PHP_Chimp for your answer.
I removed the header('Location..') and now it's working ok . I think google it's more happy now :-) . And as you mentioned I read that 410 it's much better than 404 - at least for search engines - so that's why I'm using it.
I saw on the internet the code with header('http..'); header('Location..'); for the '301 Moved Permanently'.So I thought it also works with 410. But it doesn't work.

For the moment I'll not use $_SERVER['SERVER_PROTOCOL'] - I'll just use .htaccess. Anyway it's a good idea.
Thanks again.