在我的asp.net网站上,我在web.config文件中定义了以下自定义错误页面.
<customErrors mode="On" defaultRedirect="~/defaulterror.htm" > <error statusCode="404" redirect="~/404.htm" />
当找不到文件时,它正确显示404.htm页面,但问题是当我做fiddler跟踪它返回302作为HTTP状态代码.这是搜索引擎页面索引的一个大问题,因为这些断开的链接仍然被索引最近因为这个在我的网站上.如何防止返回302作为文件未找到错误的HTTP状态代码,并返回404文件未找到错误.我正在使用asp.net 3.5.
解决方法
在谷歌搜索此问题后,似乎这是Microsoft ASP.NET为此情况提供的默认行为.这对SEO来说非常糟糕.我找到的解决方法是检查所请求的文件是否存在于HTTP处理程序(或global.asax文件)中,或使用:
<customErrors mode="On" redirectMode="ResponseRewrite"> <error statusCode="404" redirect="/FileNotFound.aspx" /> </customErrors>
如果请求的文件不存在,则将请求路径重写为未找到文件页面(如果使用HTTP处理程序或global.asax),清除404错误页面代码后面的服务器错误,并添加404错误标头手动响应而不是等待服务器这样做.
Server.ClearError(); Response.Status = "404 Not Found"; Response.StatusCode = 404;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。