繁体   English   中英

在 IIS 10(包含参数的 URL)中,http 不使用 Url Rewrite 重定向到 https 的整个 URL

[英]http not redirecting to https using Url Rewrite for whole URL in IIS 10 (URL containing parameters)

我尝试了从 IIS 控制台添加的以下配置,但这仅适用于主域
例如
适用于 - http://example.com重定向到https://example.com
但在以下情况下不起作用
http://example.com/abc/some?Parameter
不重定向到
https://example.com/abc/some?Parameter

<rewrite>
      <rules>
        <rule name="HTTP/S to HTTPS Redirect" enabled="true" stopProcessing="true">
          <match url="(.*)" />
          <conditions logicalGrouping="MatchAll">
                        <add input="{HTTPS}" pattern="^OFF$" />
                       <add input="{HTTP}" pattern="^OFF$" />
          </conditions>
          <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="true" />
        </rule>
      </rules>
    </rewrite>

根据您的 url 重写规则,我发现您同时添加了 http 和 https 条件。 这意味着无论您使用 http 还是 https,它都不会重定向到 https。

正确的url重写规则如下:

<rewrite>
    <rules>
        <rule name="Redirect to http" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
            <match url="*" negate="false" />
            <conditions logicalGrouping="MatchAny">
                <add input="{HTTPS}" pattern="off" />
            </conditions>
            <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Found" />
        </rule>
    </rules>
</rewrite>

在设置重定向配置之前,有一个非常重要的步骤应该注意。

在网站项目 --> Actions(在右边) --> Bindings 中,内容如下: Binding Content

你仔细看黄色部分,黄色部分是你原来的网络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