我发现了两种不同的重写规则来强制对IIS托管的网站使用HTTPS。 我有一个网站将托管在使用此规则的Azure应用服务上。
选项1:
<rewrite>
<rules>
<rule name="Force HTTPS" enabled="true">
<match url="(.*)" ignoreCase="false" />
<conditions>
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
选项2:
<rewrite>
<rules>
<rule name="Redirect to https">
<match url="(.*)"/>
<conditions>
<add input="{HTTPS}" pattern="Off"/>
<add input="{REQUEST_METHOD}" pattern="^get$|^head$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent"/>
</rule>
</rules>
</rewrite>
问题:
我建议阅读官方文档:
您可以找到所有属性说明。
ignoreCase –使用此属性来控制条件的模式匹配是区分大小写还是不区分大小写。
appendQueryString –指定在替换期间是否应保留当前URL的查询字符串。 默认情况下,如果未指定AppendQueryString标志,则假定它为TRUE。 这意味着来自原始URL的查询字符串将附加到替代URL。