<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="301" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_FROM_HTTPS}" pattern="^on$" negate="true" />
<add input="{HTTP_HOST}" pattern="^www.odweb.cn$" negate="true" />
</conditions>
<action type="Redirect" url="https://www.odweb.cn/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
stopProcessing=”true”当执行规则操作(即匹配的规则)并打开此标志时,这意味着不再处理后续规则,并且请求将被传递到IIS请求管道。
ignoreCase=”false”忽略大小写
MatchAny 任意匹配,成功匹配到一个就执行action 相当于or
MatchAll 完全匹配,匹配所有规则,都成立才执行action 相当于and
negate=”true”代表取反,比如HTTP_FROM_HTTPS 不等于on 为真
例子一的含义是http跳转到https,比如https://odweb.cn也会跳转到https://www.odweb.cn
例子二
我有一个手机站m.odweb.cn,不想跳转到https://www.odweb.cn
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="301" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_FROM_HTTPS}" pattern="^on$" negate="true" />
<add input="{HTTP_HOST}" pattern="^m.odweb.cn$" negate="true" />
</conditions>
<action type="Redirect" url="https://www.odweb.cn/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
以上就是web.config规则http跳转到https规则的详细内容,更多信息请关注OD云其它相关文章!

喜 欢 514