[英]IIS Rewrite Rule in web.config to redirect HTTPS requests to HTTP
我需要將所有https請求重定向到http,例如,如果有人訪問https://www.example.com/another-page/ , 請訪問http://www.example.com/another-page/
我現在在web.config中有以下重寫規則,但它無法正常工作。 它將https://www.example.com/another-page/重定向到https://www.example.com/ ,所以到了網站的根目錄,但我希望重定向保留在同一個網址中將https重寫為http。
<rule name="Redirect to HTTP" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{R:1}" pattern="^onepage/(.*)$" negate="true" />
<add input="{HTTPS}" pattern="^ON$" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}/{R:0}" redirectType="Permanent" />
</rule>
任何有關更改上述規則的幫助,以便它只將https更改為http,但保持訪問的完整網址將非常感謝!
我設定了你的規則,清理了一點,它起作用了; 所以這並沒有真正回答新的問題。
建議:刪除僅用於測試的onepage
輸入條件,如cheesmacfly在問題評論中建議的那樣。
另外,嘗試將操作更改為{R:1}
而不是{R:0}
。 在這種情況下應該沒關系,但我只是喜歡使用1和更高版本來匹配特定的捕獲組。 R:0表示整個匹配的字符串,這總是讓我感到困惑。
<rule name="Redirect to HTTP" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^ON$" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
一種可能性是您的瀏覽器緩存了之前的規則嘗試。 當redirectType為Permanent,並且您仍在開發或測試時,瀏覽器通常會緩存先前的規則。 清除瀏覽器緩存,和/或刪除永久,和/或以隱身模式瀏覽。 完成測試后,將其更改為永久性。 請參閱此答案中的第2和第3位: https : //stackoverflow.com/a/9204355/292060
請將以下代碼粘貼到web.config
文件中。
<rule name="Redirect to http" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="http://{HTTPS_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.