【问题标题】:Rewrite to https for all URLs将所有 URL 重写为 https
【发布时间】:2014-11-29 04:51:58
【问题描述】:

我正在尝试将所有访问我网站的 URL 重定向到 https。

<rewrite>
  <rules>
    <rule name="Redirect to https" stopProcessing="true">
      <match url="(.*)" ignoreCase="true" />
        <conditions>
          <add input="{HTTPS}" pattern="off" ignoreCase="true" />
        </conditions>
      <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
    </rule>
  </rules>
</rewrite>

但是,访问http://www.example.com 不会重定向。我想请求http://www.example.com 重定向到https://www.example.com

看来我的规则没有效果。条件可能不对吗?

【问题讨论】:

    标签: .net iis web-config rewrite


    【解决方案1】:

    这里是一个例子:更多看Rewrite URLs on an HTTPS page to HTTP

    <rule name="ForceHttpToHttps" preCondition="ResponseIsHtml1">
    <match filterByTags="A, Img" pattern="^(?!.*javascript).*$" />
        <conditions>
            <add input="{HTTP}" pattern="ON" />
            <add input="{SERVER_PORT}" pattern="443" />
        </conditions>
    <action type="Rewrite" value="https://{HTTP_HOST}:1860{R:0}" />
    </rule>
    

    【讨论】:

    • 这导致了“HTTP 错误 500.52 - URL 重写模块错误”。并在 XML 中加载大量未知标签。
    猜你喜欢
    • 2013-01-22
    • 1970-01-01
    • 2016-12-03
    • 2017-02-24
    • 2014-09-20
    • 2011-06-02
    • 2011-09-19
    • 2013-12-03
    • 2013-12-07
    相关资源
    最近更新 更多