Redirect 重定向重写循环过多

Redirect 重定向重写循环过多,redirect,iis,url-rewriting,Redirect,Iis,Url Rewriting,要将访问者重定向到https,我在web.config中使用了以下规则: <rewrite> <rules> <clear /> <rule name="HTTP to HTTPS redirect" stopProcessing="true"> <match url="(.*)" /> <conditions> <

要将访问者重定向到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>

你没事

但这些地址会导致错误:

  • example.com和www.example.com

  • &


有人能帮我吗?

如果你有一个无休止的重定向循环。试试这个技巧

如果您未登录,“login.php”将重定向到“login.php”。如果您未登录,“login.php”将重定向到“login.php”。如果您未登录,“login.php”将重定向到“login.php”。如果您未登录,“login.php”将重定向到“login.php”。等等


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

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

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

我希望我的访问者在每个页面上都重定向到https。另外,当他们访问(http://example.com/example.php)时,“我希望他们重定向到(https:)//example.com/example.php”