【问题标题】:web.config Index Redirectweb.config 索引重定向
【发布时间】:2011-07-29 13:17:59
【问题描述】:

我为托管在 Windows 服务器上的项目使用标准 web.config 文件。它负责 2 个任务。

  1. 它将网站的非 www 版本重定向到 www 版本。
  2. 它将索引文件重定向到根目录。

见下文:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
     <modules runAllManagedModulesForAllRequests="true" />
        <rewrite>
            <rules>
                <rule name="CanonicalHostNameRule1" stopProcessing="true">
                    <match url="index\.asp(?:l)?" />
                        <conditions>
                            <add input="{HTTP_HOST}" pattern="example\.com$" />
                        </conditions>
                        <action type="Redirect" url="http://www.example.com/" />
                </rule>
                <rule name="CanonicalHostNameRule2" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="^example\.com$" />
                    </conditions>
                    <action type="Redirect" url="http://www.example.com/{R:1}" />
                </rule>
            </rules>
        </rewrite>
  </system.webServer>
</configuration>

这很好用,除了 1 个问题。索引重定向是将所有子目录重定向到主索引。

例如:

http://www.example.com/index.asp 正在重定向到 http://www.example.com,就像它应该的那样。

但是,http://www.example.com/about/index.asp 也重定向到 http://www.example.com。我希望它重定向到http://www.example.com/about/

任何帮助将不胜感激。

【问题讨论】:

    标签: asp.net url-rewriting web-config url-rewrite-module


    【解决方案1】:

    好吧,在这里没有得到回应后,我在各种.Net论坛上发帖,终于得到了答案。此规则将修复它:

    <rule name="redirect index.asp" stopProcessing="true">
        <match url="^(\w*/)?index\.asp" />
           <conditions>
             <add input="{HTTP_HOST}" pattern="domain\.com$" />
           </conditions>
         <action type="Redirect" url="http://www.domain.com/{R:1}" />
    </rule>
    

    【讨论】:

      猜你喜欢
      • 2019-03-25
      • 1970-01-01
      • 2013-12-15
      • 1970-01-01
      • 2019-08-02
      • 2015-03-05
      • 1970-01-01
      • 1970-01-01
      • 2010-11-04
      相关资源
      最近更新 更多