Forum Moderators: phranque

Message Too Old, No Replies

404 response code and redirect

Can it be done

         

adb64

9:27 pm on Nov 10, 2005 (gmt 0)

10+ Year Member



On one of my pages there is a link to a page that currently does not exist but may be added in the near future. It is being used in the following way:

h**p://www.mysite.com/index.php?Id=xyz

When the content with Id=xyz does not exist the index page itself is shown with a directory of possible Ids.

What response code should I return when a visitor clicks that link?
I was thinking of returning a 404, but instead of showing my custom error page I want to redirect them to the base index page:


header("HTTP/1.0 404 Not Found");
header("Location: h**p://www.mysite.com/index.php");

These headers are sent by index.php in case Id is not valid. Currently I just display the Id directory in case of invalid Id but that means there are pages with duplicate content (index.php and index.php?Id=invalid).
Doing it this way with sending the headers I hope to prevent being penalized for duplicate content. Can it be done like this or is there another way to do it?

Thanks,
Arjan

adb64

9:48 pm on Nov 10, 2005 (gmt 0)

10+ Year Member



Ok, did some testing and by viewing Live HTTP headers in FF I saw that the 404 is not even send in this case. The server sends a '302 Found' response. I wonder whether that is the correct response in my situation.

jdMorgan

8:13 am on Nov 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's your choice, either return a standard 404-Not Found response, and an error page with a link to your home page or site map, or return a 302-Moved Temporarily and point it to a page that is 'close' in content and purpose to the original page.

You should consider putting up a temporary page, so that you have something meaningful to 302-redirect to. Do not 302 to your home page or site map; that will confuse the 'bots and you may end up with the temporary URL replacing your home page URL in the search results. Do this by the book [w3.org], and stay out of trouble. :)

Jim

adb64

10:48 am on Nov 11, 2005 (gmt 0)

10+ Year Member



Jim, thanks.

I already looked at that page, but I couldn't find an appropriate response for my situation. So I decided to use a 404 and redirected to my index page as I don't want visitors to end up at my 404 error page from a link in my own site. But (I assume) PHP doesn't send a 404 together with a Location header, it automagically is changed into a 302 Found response which indeed is not the correct response in my situation.

Well I'll see what I will do,

Arjan