[英]Configuring custom ASP 404 page with redirect for IIS7 website
我们正在将现有网站从IIS6迁移到IIS7,但在设置404错误页面时遇到了一些困难。 我们的404-errorpage是这样的:
有了IIS6,这就像宣传的一样,但是在IIS7中,有些东西已经改变了。 当IIS7遇到定义了errorpage的状态码时,它将始终显示已配置的错误。 如果我们的静态错误与404状态代码,这意味着IIS7将再次执行自定义ASP页面。 这导致无限重定向。
我们发现通过在Web.Config中添加设置可以避免这种行为
<system.webServer>
<httpErrors existingResponse="PassThrough" />
</system.webServer>
但是,添加此项后,我们的自定义ASP页面拒绝重定向。 在与Fiddler核实之后,似乎IIS7强制404状态代码,覆盖我们的302重定向。
谁能推荐另一种方法来解决我们的问题?
我成功使用了一个类似的设置,我从IIS 6迁移到IIS 7.我的web.config有以下部分;
<system.webServer> <httpErrors errorMode="Custom"> <remove statusCode="500" subStatusCode="-1" /> <remove statusCode="404" subStatusCode="-1" /> <error statusCode="404" prefixLanguageFilePath="" path="/302page.asp" responseMode="ExecuteURL" /> <error statusCode="500" prefixLanguageFilePath="" path="/500page.asp" responseMode="ExecuteURL" /> <error statusCode="500" subStatusCode="100" path="/500page.asp" responseMode="ExecuteURL" /> </httpErrors> <system.webServer>
我通过IIS管理器在相关站点上配置了这个,但如果您更容易,可以通过web.config文件进行配置。
您可以添加条件标头,具体取决于是301,302还是404。
404;
Response.Status = "404 Not Found"
Response.AddHeader "Location", pagename
302(临时重新直接);
Response.Status="301 Object Moved"
Response.AddHeader "Location", pagename
301(永久重新直接);
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", pagename
IIS站点的应用程序池使用集成管道模式。 并附加了网站调试部分的设置。
我在另一周遇到了类似的客户端情况。 解决方案是按如下方式配置<httpErrors>
:
<httpErrors errorMode="Custom" existingResponse="Auto">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404"
prefixLanguageFilePath=""
path="/404.asp"
responseMode="ExecuteURL" />
<remove statusCode="500" subStatusCode="100" />
<error statusCode="500"
subStatusCode="100"
prefixLanguageFilePath=""
path="/500-100.asp"
responseMode="ExecuteURL" />
</httpErrors>
这适用于Cactushop(用经典ASP编写),它具有“友好”的URL,并且他们使用404处理程序页面来解析URL并呈现产品或列出产品类别等等。
或者,您可以查看使用IIS插件模块: URLRewrite 。 这将允许您设置自定义SEO友好URL。 您可能会发现这个想要查看的内容以改进您的应用程序,而不是修复您现有的问题,因为可能需要一些时间来学习。
有一些优秀的文章, 视频教程和如何使用此工具的信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.