我在我网站的某个文件夹中的web.config中使用此代码将所有页面重定向到根目录,因为我想永久关闭此部分。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location>
<system.webServer>
<httpRedirect enabled="true" destination="http://www.example.com/" httpResponseStatus="Permanent" />
</system.webServer>
</location>
</configuration>
但我需要对此规则进行例外处理:我不希望我的页面“default.aspx”被重定向。我怎么能这样做?
答案 0 :(得分:38)
将Default.aspx设置为<location>
,并禁用httpRedirect。如果您在<location>
之前或之后放置<system.webServer>
无关紧要。
<configuration>
<system.webServer>
<httpRedirect enabled="true" destination="http://www.example.com/" exactDestination="true" httpResponseStatus="Permanent" />
</system.webServer>
<location path="Default.aspx">
<system.webServer>
<httpRedirect enabled="false" />
</system.webServer>
</location>
</configuration>
答案 1 :(得分:12)
您可以按以下方式添加通配符,以仅重定向某些文件:
<configuration>
<system.webServer>
<httpRedirect enabled="true" exactDestination="true" httpResponseStatus="Found">
<add wildcard="*.php" destination="/default.htm" />
</httpRedirect>
</system.webServer>
</configuration>
但是我不确定你是否可以否定它,所以它忽略了某个文件。