本文介绍了IIS 将非 www 重定向到 www 并将 http 重定向到 https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试为 IIS 实现两个规则,将非 WWW 重定向到 WWW,将 http 重定向到 https.
i'm trying to implement two rules for IIS to Redirect non-WWW to WWW and http to https.
zzz -> www.zzz www.zzz -> www.zzz zzz -> www.zzz所以,我将其添加到我的 web.config 中:
So, i added this to my web.config:
<system.webServer> <rewrite xdt:Transform="Insert"> <rules> <rule name="Force WWW" enabled="true"> <match url="(.*)" /> <conditions> <add input="{HTTP_HOST}" pattern="^[^www]" /> </conditions> <action type="Redirect" url="www.zzz/{R:1}" appendQueryString="true" redirectType="Permanent" /> </rule> <rule name="Force HTTPS" enabled="true"> <match url="(.*)" /> <conditions> <add input="{HTTPS}" pattern="off" /> </conditions> <action type="Redirect" url="www.zzz/{R:1}" appendQueryString="true" redirectType="Permanent" /> </rule> </rules> </rewrite>我的问题:
有什么办法可以将其合并为一个规则吗?
Is there any way to combine this in one rule?
推荐答案是的,您可以将它们合并为一个,并使用逻辑分组作为条件并将其设置为 Any ,这相当于OR".例如:
Yes you can merge them into one and use the logicalGrouping for the conditions and set it to Any which would be the equivalent of an "OR". For example:
<rule name="Force WWW and SSL" enabled="true" stopProcessing="true"> <match url="(.*)" /> <conditions logicalGrouping="MatchAny"> <add input="{HTTP_HOST}" pattern="^[^www]" /> <add input="{HTTPS}" pattern="off" /> </conditions> <action type="Redirect" url="www.zzz/{R:1}" appendQueryString="true" redirectType="Permanent" /> </rule>更多推荐
IIS 将非 www 重定向到 www 并将 http 重定向到 https
发布评论