【问题标题】:Multiple URL Rewrite rules getting conflicted多个 URL 重写规则发生冲突
【发布时间】:2012-09-01 01:57:35
【问题描述】:

我遇到以下情况,网址重写规则相互冲突:

  1. 规则 1:我需要将我的域重定向到 https
  2. 规则 2:我需要重定向 www.mydomain.com --> https://mydomain.com
  3. 规则 3:我需要将 www.mydomain.com 和 mydomain.com 都重定向到 https://mydomain.com/myfolder,但如果我有 mydomain.com/mysecondfolder,则应该只重定向到 https://mydomain.com/mysecondfolder

除了将 www.mydomain.com 重定向到 https://mydomain.com 之外,我所能实现的就是一切(只是因为它与其他规则发生冲突,如果它单独工作的话)。

我的规则是:

<rule name="HTTP to HTTPS redirect" stopProcessing="true">
              <match url="(.*)" />
                <conditions>
                    <add input="{HTTPS}" pattern="off" />
                </conditions>
              <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
            </rule> 

            <rule name="redirect to myfolder" enabled="true">
                <match url="^$" />
                <conditions>
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                </conditions>
                <action type="Rewrite" url="/myfolder" />
            </rule>

【问题讨论】:

    标签: iis iis-7 url-rewriting url-redirection


    【解决方案1】:

    我可以使用以下规则解决这个问题:

    <rewrite>
                <rules>
                <rule name="Canonical Host Name" enabled="true" stopProcessing="true">
                  <match url="(.*)" />
                  <conditions>
                    <add input="{HTTP_HOST}" negate="true" pattern="^myapp\.com$" />
                  </conditions>
                  <action type="Redirect" url="http://myapp.com/{R:1}" redirectType="Permanent" />
                </rule>
                    <rule name="HTTP to HTTPS redirect" enabled="true" stopProcessing="true">
                      <match url="(.*)" />
                        <conditions>
                            <add input="{HTTPS}" pattern="off" />
                        </conditions>
                      <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
                    </rule> 
                    <rule name="redirect to items" enabled="false">
                        <match url="^$" />
                        <conditions>
                            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        </conditions>
                        <action type="Rewrite" url="/items" />
                    </rule>
    
                </rules>
            </rewrite>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-21
      • 1970-01-01
      • 2012-06-09
      • 2021-08-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多