2017-04-11 85 views
0

重定向我的客人到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都沒問題。

但這些地址導致錯誤:

誰能幫助我?

回答

0

我發現在這些規則中的解決方案:

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

如果你有一個無止境的重定向循環。試試這個提示。

如果您未登錄,「login.php」將重定向到「login.php」。如果您未登錄,「login.php」將重定向到「login.php」。「login.php」重定向如果你沒有登錄,登錄「login.php」。「login.php」重定向到「login.php」等。

你應該使重定向只發生在當前頁面不是「login.php」;即從該頁面刪除該邏輯。

+0

我想我的訪問者重定向到https每一頁上。另外,當他們訪問(http:)// example.com/example.php'我希望他們重定向到(https:)// example.com/example.php' – FredV