[英]Root page has forced redirect to http protocol or how to exclude root page from redirection to https
我可以訪問 IIS 應用程序,但我不知道是誰創建和部署了它。 但我需要讓這個應用程序通過https協議工作。 我創建了 let's encrypt 證書並將其應用到網站。 如果我關注一些 URL,例如: https://example.com/aboutus
等等 - 它會按預期工作。 但是當我嘗試訪問https://example.com
時,它強行將我重定向到http://example.com
。 然后,當我通過導航菜單訪問其他頁面時,它們是http://example.com/about_us
等等,除了少數頁面被強制重定向到https
,例如https://example.com/sign_up
和sign_in
.
如果我應用以下規則:
<rule name="Redirect to HTTPS" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" />
</rule>
所有頁面都被重定向,但由於硬編碼重定向而無法加載主頁:
我不知道它是否在某處進行了硬編碼。 但目前我想將除主頁以外的所有內容重定向到https 。 我該怎么做?
此處的答案不適用於我的情況
這也不起作用:
<rule name="Redirect to HTTPS" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
<add input="{URL}" pattern="example\.com\/.+" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" logRewrittenUrl="true" />
</rule>
可以參考這個規則,使用{HTTP_HOST}變量匹配根頁面,然后通過negate屬性取反。
<rule name="Redirect to HTTPS except root page" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^http://example.com$" negate="true" />
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
</rule>
通過遵循 Lex Li 關於使用 FRT 的建議,我發現 URL Rewrite 模塊適用於相對路徑。 例如, http://example.com/about_us
只是/about_us
,因此我的pattern="example\.com\/.+"
不起作用。
以下規則按預期工作:
<rule name="Redirect to HTTPS" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{URL}" pattern="\/.+" />
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
</rule>
所有帶有http
協議的頁面以/
開頭並且后面至少有一個符號,應該被重定向。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.