【问题标题】:http not redirecting to https using Url Rewrite for whole URL in IIS 10 (URL containing parameters)http 不使用 IIS 10 中的整个 URL 的 URL 重写重定向到 https(包含参数的 URL)
【发布时间】:2021-01-05 11:54:10
【问题描述】:

我已尝试从 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>

【问题讨论】:

标签: c# http redirect iis url-rewriting


【解决方案1】:

根据您的 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>

【讨论】:

    【解决方案2】:

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

    在 web Sites 项目中 --> Actions(in the right) --> 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>
    

    【讨论】:

      猜你喜欢
      • 2016-03-20
      • 2011-12-11
      • 2013-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-07
      • 2016-02-26
      相关资源
      最近更新 更多