我知道这个问题被问了1000次,但是其他答案都没有帮助,所以我们来了。
我需要重定向:
http://example.com至https://www.example.com
http://www.example.com至https://www.example.com
这是我的规则:
<rule name="HTTP Redirect to HTTPS" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="on" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
</rule>
<rule name="Redirect to WWW" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^example.com$" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:0}" redirectType="Permanent" />
</rule>
结果:
http://example.com重定向到https://www.example.com
http://www.example.com重定向到http://www.example.com(无SSL)
我似乎无法正常工作。
任何帮助表示赞赏。谢谢!
答案 0 :(得分:0)
我认为问题出在您最初的HTTP to HTTPS规则上。
尝试一下:
<rule name="HTTP Redirect to HTTPS" patternSyntax="Wildcard" enabled="true" stopProcessing="true">
<match url="*" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Found" />
</rule>
<rule name="Redirect to WWW" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^example.com$" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:0}" redirectType="Permanent" />
</rule>