views:

417

answers:

8

I have a situation where some users may come to mistyped pages, from links, etc. In most situations I can determine the correct page that should be displayed, so I want to redirect to the correct URL.

Is a 301 Redirect appropriate in this case. 301 means "Moved Permanently", but in this case the document wasn't there in the first place. Is it legitimate to set a 404 Not Found header, then redirect to the correct URL?

A: 

you can't redirect with a 404 document. maybe just display a 404 page and suggest some correct URL's. 404 means error. I know google won't be happy seeing those links. :)

TheBrain
Actually, you can. The HTTP status header is a different one to the location header, so you can replace it with 404 header + new URL. Doesn't mean it's a good idea though, which is what the question was asking.
DisgruntledGoat
A: 

You can only respond once to an http request - you can't send a 404, and then send a 301. So you are stuck with the 301, I think.

Ray
A: 

Either use a 301 and do the redirect, or use a 404 and display a message along the lines of "I think you mean 'this URL' instead; update your bookmarks" (and don't redirect).

Chris J
+3  A: 

I'd use 301. Moved permanently is appropriate in that it tells the accessed page is not there and never will be. If someone has a link to that page, they then know they should update the link.

Carlos
You don't know there never will be a page at that particular URL.
Martin Hohenberg
True. Though in many cases you can make a good guess. I wouldn't be that worried about it.
Carlos
My situation is similar to Stack Overflow, in that only part of the URL actually defines the content. Therefore, the mistyped page will never exist.
DisgruntledGoat
+5  A: 

Beware of 301, as it means "permanently", e.g. even if you use that URL in the future, search engines might want to disregard it - as they "know" the content at that particular URL was moved "permanently".

Use 303 See Other if you want the redirect, or - better - display 404 and a friendly error-message that links to the preferred content.

Martin Hohenberg
+1  A: 

301 is perfectly appropriate when you are reasonably sure you know what the URL was supposed to be. It's the best solution both for browsers and for SEO when faced with broken incoming links.

However 3xx is inappropriate as a general page-not-found response. There are some sites that always 302 you to / instead of returning 404, but this is a really bad thing that can easily break stuff.

bobince
+1  A: 

I know a 404 can include a redirect header but that sounds really bad to me.

Joshua
+2  A: 

I think bringing the user to a "did you mean" type of page would be my preference. If you have no suggestions for the "did you mean" content, then give them a real error page and 404 it. Otherwise, leave the pages as status 200 and let the user click through.

I tend to use 301s to redirect previously known and well-established URLs that have changed for some reason. The reason I would worry about the automatic redirect approach is that a flaw in your detection algorithm could possible negatively impact SEO.

joseph.ferris