Sitecore使用“302 found”将用户重定向到我的自定义404页面 - 这是合法的吗? [英] Sitecore uses "302 found" to redirect users to my custom 404 page - is that legitimate?

查看:432
本文介绍了Sitecore使用“302 found”将用户重定向到我的自定义404页面 - 这是合法的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个HTTP规范问题,而不是Sitecore问题。

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

我在Sitecore中设置了404错误页面:

I have a 404 error page set up in Sitecore:

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

因此,当用户访问不存在的页面时(例如www.example.com/xyz)它们被重定向到我的自定义404页面(例如www.example.com/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使用302执行重定向,如下面的Firebug屏幕截图所示:

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

这是一个问题吗?即Google和其他搜索引擎会将我的404页面编入网址www.example.com/xyz吗?有问题的网站最初设置为从404页面返回200 OK响应(不好!),因此搜索引擎一旦找到网站中的链接断开,就会将网站编入索引页面。

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.

我认为因为302只是一个重定向,所以最终(自定义404)URL的状态代码将是任何客户端应该假定适用于初始(重定向)的URL。

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?

推荐答案

这确实是一个问题。因为谷歌现在认为 404.aspx 页面不存在,并且会认为暂时重定向不存在的项目。

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.

它的作用基本上是确定该项目不存在(通过管道处理器),然后通过使用WebRequest请求它来检索404页面的内容,并使用404状态代码将该内容返回给浏览器。

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.

这篇关于Sitecore使用“302 found”将用户重定向到我的自定义404页面 - 这是合法的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆