如何将 HTTP IIS7 响应“403 禁止”重定向到 HTTPS?

Jan*_*nda 6 iis iis-7

我要求我们的网络主机在我们的网站上设置 SSL,这样 HTTP 请求将自动重定向到 HTTPS。

他们说这已经完成,但是当通过 HTTP 访问该站点时,我现在得到:

Response HTTP/1.1 403 Forbidden
Run Code Online (Sandbox Code Playgroud)

HTTPS 工作正常。

我要求更正这个问题,我被告知这不是服务器设置(由他们管理),需要通过 web.config(我可以访问)进行修复。

我尝试使用以下更改来捕获此 403 并将其重定向,但未成功:

<system.web>
    <customErrors defaultRedirect="/test.html" mode="On"></customErrors>
</system.web>

<httpErrors errorMode="Custom">
    <remove statusCode="403" subStatusCode="-1" />
    <error statusCode="403" prefixLanguageFilePath="" path="/test.html" responseMode="ExecuteURL" />
</httpErrors>  
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题,以便 HTTP 将重定向到 - 实际上需要 - HTTPS?

Jan*_*nda 7

原来主机必须先取消选中“需要 SSL”,然后我才能通过以下方式重定向 web.config 中的流量:

<rule name="HTTP to HTTPS redirect" stopProcessing="true">
  <match url="(.*)" />
    <conditions>
      <add input="{HTTPS}" pattern="off" ignoreCase="true" />
    </conditions>
 <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
</rule>
Run Code Online (Sandbox Code Playgroud)