我是一名php开发人员,但必须对asp网站进行一些更改。我试图将404错误重定向到自定义404页面。下面是web.config页面的代码:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<security>
<requestFiltering>
<filteringRules>
<!-- name the rule -->
<filteringRule name="user agent deny" scanUrl="false" scanQueryString="false">
<scanHeaders>
<!-- apply rule to user-agent header -->
<add requestHeader="user-agent" />
</scanHeaders>
<!-- apply rule to all files -->
<appliesTo />
<denyStrings>
<clear />
<!-- block the following bots -->
<add string="Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots) " />
<add string="Mozilla/5.0 (compatible; YandexImages/3.0; +http://yandex.com/bots) " />
<add string="Mozilla/5.0 (compatible; YandexBot/3.0; MirrorDetector; +http://yandex.com/bots) " />
<add string="Mozilla/5.0 (compatible; YandexMedia/3.0; +http://yandex.com/bots) " />
<add string="Mozilla/5.0 (compatible; YandexBlogs/0.99; robot; +http://yandex.com/bots) " />
<add string="Mozilla/5.0 (compatible; YandexVideo/3.0; +http://yandex.com/bots) " />
<add string="Mozilla/5.0 (compatible; YandexZakladki/3.0; +http://yandex.com/bots) " />
<add string="Mozilla/5.0 (compatible; YandexAntivirus/2.0; +http://yandex.com/bots) " />
<add string="Mozilla/5.0 (compatible; YandexFavicons/1.0; +http://yandex.com/bots) " />
<add string="Mozilla/5.0 (compatible; YandexDirect/3.0; +http://yandex.com/bots) " />
<add string="Mozilla/5.0 (compatible; YandexCatalog/3.0; +http://yandex.com/bots) " />
<add string="Mozilla/5.0 (compatible; YandexImageResizer/2.0; +http://yandex.com/bots) " />
<add string="Yandex/1.01.001 (compatible; Win16; I) " />
<add string="Yandex/1.01.001 (compatible; Win16; H) " />
<add string="Mozilla/5.0 (compatible; YandexWebmaster/2.0; +http://yandex.com/bots) " />
<add string="Yandex/1.01.001 (compatible; Win16; P) " />
<add string="Yandex/1.01.001 (compatible; Win16; m) " />
<add string="YandexSomething/1.0 " />
<add string="Baiduspider+(+http://www.baidu.com/search/spider.htm) " />
<add string="BaiduImagespider+(+http://www.baidu.jp/search/s308.html) " />
<add string="BaiDuSpider " />
<add string="Baiduspider+(+http://help.baidu.jp/system/05.html) " />
<add string="Baiduspider+(+http://www.baidu.com/search/spider_jp.html) " />
<add string="Baiduspider+(+http://www.baidu.jp/spider/) " />
</denyStrings>
</filteringRule>
</filteringRules>
</requestFiltering>
</security>
<staticContent>
<clientCache cacheControlMaxAge="365.00:00:00" cacheControlMode="UseMaxAge" />
</staticContent>
<defaultDocument>
<files>
<clear />
<add value="index.asp" />
<add value="Default.asp" />
<add value="Index.html" />
<add value="Index.htm" />
<add value="Index.cfm" />
<add value="Index.shtml" />
<add value="Index.shtm" />
<add value="Index.stm" />
<add value="Index.php" />
<add value="Index.php3" />
<add value="Index.aspx" />
<add value="Default.htm" />
<add value="Default.aspx" />
</files>
</defaultDocument>
<rewrite>
<rules>
<rule name="Redirect to WWW" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^thetoolstore.ca$" />
</conditions>
<action type="Redirect" url="http://www.thetoolstore.ca/{R:0}" redirectType="Permanent" />
</rule>
<rule name="Redirect to root" patternSyntax="Wildcard" stopProcessing="true">
<match url="index.asp" />
<action type="Redirect" url="/" appendQueryString="false" redirectType="Permanent" />
</rule>
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
<httpErrors errorMode="Detailed" />
</system.webServer>
<system.net>
<mailSettings>
<smtp from="info@thetoolstore.ca">
<network host="localhost" />
</smtp>
</mailSettings>
</system.net>
我尝试添加代码,例如:
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" path="404.asp" responseMode="ExecuteURL"/>
</httpErrors>
但这只会产生500错误。实际上,我试过的任何东西都会产生500错误。
另外,我很确定这不是MVC网站,如果有帮助的话。
谢谢!
答案 0 :(得分:0)
它会给您500错误,因为web.config文件本身格式错误。它缺少结束标记</configuration>
。
还有一个现有的httpErrors节点<httpErrors errorMode="Detailed" />
。这必须替换为您的代码(有效)。不可能有重复。
最后请使用类似http://www.freeformatter.com/xml-formatter.html的内容来正确格式化该web.config文件。这是一团糟。