Is a “404 redirect” a legitimate redirect?

2019-06-27 13:21发布

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?

8条回答
闹够了就滚
2楼-- · 2019-06-27 13:53

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.

查看更多
冷血范
3楼-- · 2019-06-27 13:59

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.

查看更多
登录 后发表回答