IIS:将所有 URL 的 HTTP 重定向到 HTTPS

IIS:将所有 URL 的 HTTP 重定向到 HTTPS

对于我们的网站(Windows Server 2016 Datacenter,IIS 10),我们使用两个不同的 URL - 比如说,url1.com使用url2.com相同的根目录和相同的应用程序池。

在我们的 web.config 中我们定义了一个重定向

<rules>
  <rule name="Redirect to HTTPS" stopProcessing="true" xdt:Transform="Insert" >
    <match url="^(.*)$" />
    <conditions>
      <add input="{HTTPS}" pattern="^OFF$" />
      <add input="{HTTP_HOST}" matchType="Pattern" pattern="^localhost(:\d+)?$" negate="true" />
      <add input="{HTTP_HOST}" matchType="Pattern" pattern="^127\.0\.0\.1(:\d+)?$" negate="true" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
  </rule>
</rules>

这适用于所有类似url1.com、和 的请求,http://url1.comhttp://www.url1.com不适用于url2.com。在我们的浏览器中输入 url2.com 会导致http://url2.com,从而导致错误 403 。

怎么了?

答案1

经过一番思考,问题解决了:详细的(IIS)错误号为 403.4 - 需要 SSL。这意味着我的请求已被 IIS 拒绝,无法到达我们的网站。因此,无法将请求重定向到 https:// url2.com

在 IIS 管理器中,我发现此 URL 已选中“需要 SSL”。取消选中此框解决了我的问题。

相关内容