繁体   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