【问题标题】:IIS 8.5 URL Rewrite force redirect http --> https for non wwwIIS 8.5 URL 重写强制重定向 http --> https 用于非 www
【发布时间】:2015-03-13 16:56:03
【问题描述】:

我从重写模块开始遇到“简单”IIS 8.5 URL 重写重定向 http --> https 对于非 www 站点的问题。

问题:如果域与操作 url 参数匹配,我总是得到“http://”而不是“https://”。

这是我的规则:

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

我无法发布多个链接,因此“域”= crm.test.com。具有重写规则的站点在 2080 端口上绑定到“domain”=crm.test.com。

我想将“http://”重定向到“https://”,但我总是得到“http://”作为响应位置:

   HTTP/1.1·302·Redirect
   Connection:·close
   Content-Length:·176
   Date:·Thu,·15·Jan·2015·08:21:21·GMT
   Location:·http://domain/                      <--
   Content-Type:·text/html;·charset=UTF-8
   Server:·Microsoft-IIS/8.5
   X-Powered-By:·ASP.NET

我尝试了以下动作url参数:

不工作:

"https://{HTTP_HOST}/{R:1}" -> http://domain/
"https://domain/{R:1}" -> http://domain/
"https://{HTTP_HOST}:443/{R:1}" -> http://domain/
"https://{HTTP_HOST}/1" -> http://domain/1/

工作:

"https1://{HTTP_HOST}/{R:1}" -> https1://domain/
"https://{HTTP_HOST}:444/{R:1}" -> https://domain:444/
"https://test.domain.com/{R:1}" -> https://test.domain.com/
"https://www.google.com/{R:1}" -> https://www.google.com/

我找到了“URL Rewrite on IIS from http to https is not working,”,但这并不能解决我的问题。

我错过了什么吗?

【问题讨论】:

    标签: redirect iis https url-rewriting rewrite


    【解决方案1】:

    以下对我们有用:

                <rule name="HTTP Redirect to HTTPS" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{HTTPS}" pattern="^OFF$" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
                </rule>
    

    【讨论】:

    • 对不起,与此配置相同的结果。谢谢马丁
    • 您是将其添加到全局规则还是每个网站规则?如果 "https://{HTTP_HOST}:443/{R:1}" -> domain 不起作用,但 "https://{HTTP_HOST}:444/{R:1}" -> domain:444确实如此,那么也许你有另一个更高的规则阻止这条规则被击中?
    • 这是本地规则,也是我得到的唯一规则。我设置了一个aspx网页尝试从这里重定向,发现如果链接包含requestet主机,页面上的所有链接都会自动从http更改为https。这似乎是问题所在,也许它不是重写模块。谢谢马丁
    【解决方案2】:

    哦。 k.,我找到了解决方案 - 链接翻译是由 iis 前面的 tmg 2010 引起的。 tmg 有一个错误,在 301 的情况下,链接翻译会将 https 链接重置为 http。此处描述了问题的解决方案:

    http://blog.sanibellogic.com/2008/09/default

    http://support.microsoft.com/kb/924373

    谢谢大家。

    【讨论】:

      【解决方案3】:

      您还可以使用 URL 重写配置带或不带 www 的重定向域。 SSL 证书仅包括:www FQDN。

      web.config 示例(域示例为:sysadmit.com):

      <rewrite>
          <rules>
          <clear />
             <rule name="Force WWW and SSL" enabled="true" stopProcessing="true">
          <match url="(.*)" />
          <conditions logicalGrouping="MatchAny">
              <add input="{HTTP_HOST}" pattern="^[^www]" />
              <add input="{HTTPS}" pattern="off" />
          </conditions>
          <action type="Redirect" url="https://www.sysadmit.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
      </rule>
      </rules>
      </rewrite>
      

      摘自:http://www.sysadmit.com/2017/05/windows-iis-redirigir-http-https.html

      【讨论】:

        猜你喜欢
        • 2013-06-11
        • 2015-09-11
        • 2018-07-25
        • 2016-05-08
        • 2019-12-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多