【问题标题】:Too many redirects rewrite loop太多重定向重写循环
【发布时间】:2017-04-11 08:36:05
【问题描述】:

为了将我的访问者重定向到 https,我在 web.config 中使用了这个规则:

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

但是当我尝试访问该网站时出现错误(重定向太多),它似乎陷入了一个循环。

https://example.comhttps://www.example.com 都可以。

但是这些地址会导致错误:

谁能帮我解决这个问题?

【问题讨论】:

    标签: redirect iis url-rewriting


    【解决方案1】:

    如果您有一个无限循环的重定向。试试这个技巧。

    “login.php”如果你没有登录,会重定向到“login.php”。如果你没有登录,“login.php”会重定向到“login.php”。“login.php”会重定向到“login.php”如果你没有登录。“login.php”重定向到“login.php”如果你没有登录。等等

    您应该只在当前页面不是“login.php”时才进行重定向;即从此页面中删除该逻辑。

    【讨论】:

    • 我希望我的访问者在每个页面上都重定向到 https。此外,当他们访问 (http:)//example.com/example.php' 我希望他们重定向到 (https:)//example.com/example.php'
    【解决方案2】:

    我在这些规则中找到了解决方案:

        <rules>
           <clear />
             <rule name="Redirect to HTTPS" stopProcessing="true">
                  <match url="(.*)" />
                  <conditions>
                    <add input="{HTTP_HOST}" pattern="^example\.com$" negate="true" />
                    <add input="{HTTPS}" pattern="OFF" ignoreCase="true" />
                  </conditions>
                  <action type="Redirect" url="http://example.com/{R:1}" />
                </rule>
                <rule name="Redirect to WWW" stopProcessing="true">
                  <match url=".*" />
                  <conditions logicalGrouping="MatchAny">
                    <add input="{HTTP_HOST}" pattern="^example\.com$" />
                  </conditions>
                  <action type="Redirect" url="https://www.example.com/{R:0}" redirectType="Permanent" />
                </rule>
            </rules>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-08
      • 1970-01-01
      • 1970-01-01
      • 2012-07-05
      • 2015-09-08
      • 1970-01-01
      • 2012-03-05
      • 2013-01-25
      相关资源
      最近更新 更多