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?
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.
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.
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.
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. :)
I know a 404 can include a redirect header but that sounds really bad to me.
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).