[英]redirect http to https Infinity loop 301 IIS(load balancing environment)
這是重寫規則的碎片
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://www.example.com/TEST_SITE/{R:1}"
redirectType="Permanent" />
</rule>
</rules>
我的目的是測試將 http 重定向到 https 是否在我的測試站點上有效,但是,它將是一個無限循環,代碼為 301(永久移動)
如果我將 url="https://www.example.com/ TEST_SITE /{R:1} 更改為 url="{HTTP_HOST}/{R:1}",它將起作用,不再循環。但不是將我重定向到https://www.example.com/TEST_SITE/ ,它將我重定向到https://www.example.com/ (生產環境)。
任何想法來解決這個問題? 謝謝
愚蠢的我昨天沒想到這個...添加您的域名/ HTTP_HOST 作為輸入條件。
這來自我網站上的一個真實例子:
<!-- redirect HTTP naar HTTPS for WordPress https://www.saotn.org/ssl-wordpress-move-wordpress-site-https-definitive-guide/ -->
<!-- see https://www.saotn.org/redirect-http-to-https-on-iis/ and
https://www.saotn.org/iis-url-rewrite-redirect-http-to-https/ for more
information -->
<rule name="example.com http to https" stopProcessing="true">
<match url="(.*)" ignoreCase="true" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^(www.)?example\.com$" />
<add input="{HTTPS}" pattern="off" />
<add input="{URL}" pattern="(.*)" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:1}" redirectType="Permanent" />
</rule>
您的TEST_SITE
應該在{URL}
輸入模式中,在{R:1}
捕獲。
請試試這個
<rule name="HTTP To HTTPS" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="OFF" />
<add input="{HTTP_HOST}" pattern="^(([^\.]+)\.)?example.com$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:0}" />
</rule>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.