我需要从
www.domain.de至 https://domain.de
-作品
http://www.domain.de至 https://domain.de
-作品
http://domain.de至 https://domain.de
- 不起作用
rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^www\.(.+)$" />
</conditions>
<action type="Redirect" url="https://{C:1}/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
最佳答案
我认为这对您有用,搜索模式具有可选的 www 并使用反向引用 C:2 进行重定向,该规则的条件是仅针对非 https 运行。
这是模式:
"^(www\.)?(.*)$"
在哪里:
{C:0} - www.domain.de
{C:1} - www.
{C:2} - domain.de
这是完整的规则:
<rewrite>
<rules>
<rule name="SecureRedirect" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{HTTPS}" pattern="off" />
<add input="{HTTP_HOST}" pattern="^(www\.)?(.*)$" />
</conditions>
<action type="Redirect" url="https://{C:2}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
关于redirect - iis url 将 http 重定向到非 www https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17110411/