本文介绍了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?
推荐答案
是你可以把它们合并成一个,并使用logicalGrouping的条件,并将其设置为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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!