HTTPS www重定向到web.config中

问题描述 投票:1回答:1

我在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

谢谢。

redirect iis web
1个回答
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

© www.soinside.com 2019 - 2024. All rights reserved.