Sitecore uses “302 found” to redirect users to my custom 404 page - is that legitimate?

房东的猫 提交于 2020-01-21 04:41:08

问题


This is more of a HTTP spec question than a Sitecore question.

I have a 404 error page set up in Sitecore:

<setting name="ItemNotFoundUrl" value="/404.aspx" />

So, when a user accesses a non-existent page (e.g. www.example.com/xyz) they get redirected to my custom 404 page (e.g. www.example.com/404.aspx).

Sitecore performs the redirect using a 302 as seen in the Firebug screenshot below:

Is this a problem? i.e. will Google and other search engines index my 404 page at the URL www.example.com/xyz? The site in question was originally set up to return "200 OK" responses from the 404 page (bad!) and so search engines have been indexing the sites 404 page whenever they've found a broken link into the site.

I'd assume that since 302 is just a redirect, the status code at the final (custom 404) URL will be what any client is supposed to assume applies to the initial (redirecting) URL.

If this isn't a problem, what's the canonical spec / documentation that makes that clear?


回答1:


That is a problem indeed. Because google will now think the 404.aspx page does not exist and will think the non-existing item is temporarily redirected.

I came up with a solution for this and blogged about it here.

What it does basically is determine that the item is non-existing (through a pipeline processor), then retrieve the contents of the 404 page by requesting it using a WebRequest and return that contents to the browser with a 404 status code.




回答2:


As well as what Ruud has suggested, there was a blog post by Kern Herskind that uses a Sitecore/IIS approach without having to write any additional code.




回答3:


As already mentioned correct http response headers are vital, not only for SEO but many other use cases.

There's a Sitecore Shared Source module called "Sitecore Error Manager" which makes your Sitecore installation respond with the correct 404 header and comes with a couple of other features like configuring any other error response, even for the Sitecore media library (i.e. pdf files), multilanguage support etc.

Sitecore Marketplace: http://marketplace.sitecore.net/en/Modules/Sitecore_Error_Manager.aspx

Github: https://github.com/unic/SitecoreErrorManager



来源:https://stackoverflow.com/questions/14252235/sitecore-uses-302-found-to-redirect-users-to-my-custom-404-page-is-that-legi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!