簡體   English   中英

IIS 10 URL 重寫 http 流量到 Z5E056C500A1C4B6A7110 重定向BADED

[英]IIS 10 URL Rewrite http traffic to https redirect not working

當客戶端請求 http 而不是 https 時,AWS 應用程序負載均衡器后面的 IIS 10 服務器不會重定向沒有 www 的域的流量。 指定 www 時重定向流量的規則可以正常工作,但如果您嘗試沒有 www 的相同 url,則會返回 404。

所以:

  1. 輸入“http://dname.com/blog”=404

  2. 輸入“http://www.dname.com/blog”=重定向到“https://www.dname.com/blog”

     <rule name="Force HTTPS" stopProcessing="true"> <match url="(.*)" /> <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> <add input="{HTTP_X_Forwarded_Proto}" pattern="^https$" negate="true" /> <add input="{HTTP_HOST}" pattern="^dname\.com$" /> </conditions> <action type="Rewrite" url="https://www.dname.com{REQUEST_URI}" /> </rule> <rule name="Force WWW HTTPS" enabled="true" stopProcessing="true"> <match url="(.*)" /> <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> <add input="{HTTP_X_Forwarded_Proto}" pattern="^https$" negate="true" /> <add input="{HTTP_HOST}" pattern="^www\.dname\.com$" /> </conditions> <action type="Redirect" url="https://www.dname.com{REQUEST_URI}" /> </rule>

即使在瀏覽了不同論壇上提供的答案之后,我也沒有任何效果。 經過兩天的努力,這就是我發現的解決問題的方法:

  1. 綁定:必須啟用端口 80(可以在 IIS 的綁定部分添加)。

  2. SSL 設置:必須取消選中所需的 SSL。

  3. 添加規則:

<rewrite>
    <rules>
        <rule name="http to https redirection" stopProcessing="true">
            <match url="(.*)" />
            <conditions>
                <add input="{HTTPS}" pattern="^OFF$" />
            </conditions>
            <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" 
                appendQueryString="false" />
        </rule>
    </rules>
</rewrite>
  1. 驗證 web 配置,因為它應該反映在 IIS 中添加的規則。

我不知道為什么以前發布的規則不起作用,但我能夠創建一個有效的細化規則:

            <rule name="Force HTTPS" enabled="true" stopProcessing="true">
                <match url="(.*)" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    <add input="{HTTP_X_Forwarded_Proto}" pattern="^https$" negate="true" />
                    <add input="{HTTP_HOST}" pattern="^(www\.)?dname\.com$" />
                </conditions>
                <action type="Redirect" url="https://www.dname.com{REQUEST_URI}" />
            </rule>

上述規則結合了這兩個規則,而不是在單獨的規則中查找沒有 www 的域,然后再查找帶有 www 的域。 正則表達式(www\.)告訴規則查找“www”。 問號告訴它它可能存在也可能不存在,因此包括帶有和不帶有 www 的域。

在設置重定向配置之前,有一個非常重要的步驟需要注意。

在 web Sites 項目中 --> Actions(in the right) --> Bindings,內容如下: Binding Content

你小心黃色部分,黃色部分是你原來的web IP地址。 這個原始的 IP 地址必須存在於“站點綁定”中,沒有黃色部分,URL 重定向將不再起作用

以下配置是我當前的 IIS URL 重定向設置:

    <rewrite>
        <globalRules>
            <rule name="Http redirect to Https" enabled="true" stopProcessing="true">
                <match url="(.*)" />
                <conditions logicalGrouping="MatchAny">
                    <add input="{HTTP_HOST}" pattern="localhost:8080" />   <-- the Red one should match above Site Bindings original IP address
                </conditions>
                <action type="Redirect" url="https://Your-Host-Name/{R:1}" redirectType="SeeOther" />
            </rule>
        </globalRules>
    </rewrite>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM