【问题标题】:IIS Url rewrite - unsecured www to secured wwwIIS Url 重写 - 将不安全的 www 改写为安全的 www
【发布时间】:2019-12-24 22:56:20
【问题描述】:

我的网站在 IIS 8 (V.10.0.17) 上发布,我添加了重定向到 https 的规则。

涵盖所有案例:

  1. https://example.com -> https://example.com
  2. https://www.example.com -> https://example.com
  3. www.example.com -> https://example.com
  4. example.com -> https://example.com

除了这个:

  1. http://www.example.com -> 没有重定向到https://example.com

不确定我错过了什么,这是我的 web.confing:

<system.webServer>
        <rewrite>
            <rules>
                <rule name="CanonicalHostNameRule1">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="^example\.com$" negate="true" />
                    </conditions>
                    <action type="Redirect" url="http://example.com/{R:1}" />
                </rule>
                <rule name="HttpToHttps" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTPS}" pattern="^OFF$" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>

【问题讨论】:

    标签: redirect iis url-rewriting iis-8 url-rewrite-module


    【解决方案1】:

    根据您的描述,我建议您可以尝试使用以下 url 重写规则。您应该使用 example.com 而不是 {HTTP_HOST}。由于 http_host 将是 ww.example.com 而不是 example.com。

                <rule name="CanonicalHostNameRule1">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="^example\.com$" negate="true" />
                    </conditions>
                    <action type="Redirect" url="http://example.com/{R:1}" />
                </rule>
                <rule name="HttpToHttps" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTPS}" pattern="^OFF$" />
                    </conditions>
                    <action type="Redirect" url="https://example.com/{R:1}" redirectType="SeeOther" />
                </rule>
    

    结果

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-06
      • 2018-02-02
      • 1970-01-01
      • 1970-01-01
      • 2014-12-16
      • 1970-01-01
      相关资源
      最近更新 更多