IIS 将非 www 重定向到 www 并将 http 重定向到 https [英] IIS Redirect non-www to www AND http to https
本文介绍了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.
http://zzz.com -> https://www.zzz.com
http://www.zzz.com -> https://www.zzz.com
https://zzz.com -> https://www.zzz.com
所以,我将其添加到我的 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="https://www.zzz.com/{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="https://www.zzz.com/{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="https://www.zzz.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
这篇关于IIS 将非 www 重定向到 www 并将 http 重定向到 https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文