首页 > 解决方案 > 用于多域托管的 web.config https 重定向

问题描述

我有一个 GoDaddy 多网站托管帐户,现在我已经实施了 SSL,我希望所有具有 SSL 的域现在都重定向到 https。GoDaddy 说 web.config 需要修改,但他们没有关于如何为多个域执行此操作的示例。

我已经尝试了以下代码,该代码适用于托管帐户上的主域 (domainA),但随后它弄乱了该帐户上托管的所有其他域的所有 URL。例如http://domainA.com重定向到https://domainA.com但使用此代码实现http://domainB.com重定向到https://domainB.com/domainB/ - domainB 是子文件夹存储其他域文件。

<configuration>
<system.webServer>
<rewrite>
<rules>
  <rule name="HTTP to HTTPS redirect" stopProcessing="true"> 
  <match url="(.*)" /> 
  <conditions> 
    <add input="{HTTPS}" pattern="off" ignoreCase="true" />
  </conditions> 
  <action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
  </rule>   
</rules>
</rewrite>
</system.webServer>
</configuration>

标签: iishttpsweb-config

解决方案


尝试https://{HTTP_HOST}{REQUEST_URI}你的行动。

此外,我会在测试时使用临时而非永久重定向。您的浏览器可能会缓存错误的重定向,这可能会非常令人沮丧,因此请务必清除缓存或使用私人浏览器窗口来测试更改。


推荐阅读