【问题标题】: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 设置为 &lt;location&gt; 并禁用 httpRedirect。 &lt;location&gt; 放在 &lt;system.webServer&gt; 之前还是之后都没有关系。

    <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>
      

      但我不确定你是否可以否定它,以便它忽略某个文件。

      【讨论】:

        猜你喜欢
        • 2014-09-11
        • 1970-01-01
        • 2015-08-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-11-30
        • 1970-01-01
        相关资源
        最近更新 更多