【问题标题】:ASP.NET httpRedirect : redirect all pages except oneASP.NET httpRedirect :重定向除一个以外的所有页面
【发布时间】:2011-11-11 15:42:26
【问题描述】:
我在我网站的一个文件夹中的 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”被重定向。我该怎么做?
【问题讨论】:
标签:
asp.net
web-config
http-redirect
【解决方案1】:
将您的 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>
【解决方案2】:
您可以通过以下方式添加通配符,以仅重定向某些文件:
<configuration>
<system.webServer>
<httpRedirect enabled="true" exactDestination="true" httpResponseStatus="Found">
<add wildcard="*.php" destination="/default.htm" />
</httpRedirect>
</system.webServer>
</configuration>
但我不确定你是否可以否定它,以便它忽略某个文件。