HTTPS www重定向到web.config中

时间:2017-12-21 16:52:17

标签: redirect iis web

我在web.config中有以下内容强制使用https;

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

但我想强迫www。以及所有这些都将转到https://www版本。我需要实现的目标:

http://www.domain.tld/whatever
http://(no-www)domain.tld/whatever
https://(no-www)domain.tld/whatever

谢谢。

1 个答案:

答案 0 :(得分:0)

此规则将执行以下操作:

  • 重定向到HTTPS
  • 强制www

<rule name="Redirect to https" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" pattern="off" />
<add input="{HTTP_HOST}" pattern="^www." negate="true" />
</conditions>
<action type="Redirect" url="https://www.example.com{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>

您只需要使用您的域名

更改www.example.com即可
相关问题