IIS 将非 www 重定向到 www 并将 http 重定向到 https

编程入门 行业动态 更新时间:2024-10-24 14:21:39
本文介绍了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

本文发布于:2023-07-16 03:49:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1117551.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   并将   www   IIS   http

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!