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

I have tried below configuration added from IIS console, but this works only for main domain我尝试了从 IIS 控制台添加的以下配置,但这仅适用于主域
For example例如
works for- http://example.com redirects to https://example.com适用于 - http://example.com重定向到https://example.com
but not working in following case但在以下情况下不起作用
http://example.com/abc/some?Parameter http://example.com/abc/some?Parameter
not redirecting to不重定向到
https://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>

According to your url rewrite rules, I found you add both http and https condition.根据您的 url 重写规则,我发现您同时添加了 http 和 https 条件。 That means no matter you use http or https, it will always not redirect to https.这意味着无论您使用 http 还是 https,它都不会重定向到 https。

The right url rewrite rule is as below:正确的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>

There is a very very important step that should take care, before setup a redirect configure.在设置重定向配置之前,有一个非常重要的步骤应该注意。

in web Sites project --> Actions(in the right) --> Bindings , the content will like below: Binding Content在网站项目 --> Actions(在右边) --> Bindings 中,内容如下: Binding Content

You take carefully the yellow color part, the yellow part is your original web IP address.你仔细看黄色部分,黄色部分是你原来的网络IP地址。 This original IP address must exist in "Site Bindings", without the yellow part the URL redirect will not working anymore .此原始 IP 地址必须存在于“站点绑定”中,如果没有黄色部分,URL 重定向将不再起作用

The following config is my current IIS URL redirect setting:以下配置是我当前的 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