西数超哥博客
运维经验教程分享

web.config规则http跳转到https规则

例子一

  1. <?xml version=“1.0” encoding=“UTF-8”?>
  2. <configuration>
  3. <system.webServer>
  4. <rewrite>
  5. <rules>
  6. <rule name=“301” stopProcessing=“true”>
  7. <match url=“^(.*)$” ignoreCase=“false” />
  8. <conditions logicalGrouping=“MatchAny”>
  9. <add input=“{HTTP_FROM_HTTPS}” pattern=“^on$” negate=“true” />
  10. <add input=“{HTTP_HOST}” pattern=“^www.idiyrom.com$” negate=“true” />
  11. </conditions>
  12. <action type=“Redirect” url=“https://www.idiyrom.com/{R:1}” redirectType=“Permanent” />
  13. </rule>
  14. </rules>
  15. </rewrite>
  16. </system.webServer>
  17. </configuration>

stopProcessing=”true”当执行规则操作(即匹配的规则)并打开此标志时,这意味着不再处理后续规则,并且请求将被传递到IIS请求管道。

ignoreCase=”false”忽略大小写

MatchAny 任意匹配,成功匹配到一个就执行action 相当于or

MatchAll 完全匹配,匹配所有规则,都成立才执行action 相当于and

negate=”true”代表取反,比如HTTP_FROM_HTTPS 不等于on 为真

例子一的含义是http跳转到https,比如https://idiyrom.com也会跳转到https://www.idiyrom.com

例子二

我有一个手机站m.idiyrom.com,不想跳转到https://www.idiyrom.com

  1. <?xml version=“1.0” encoding=“UTF-8”?>
  2. <configuration>
  3. <system.webServer>
  4. <rewrite>
  5. <rules>
  6. <rule name=“301” stopProcessing=“true”>
  7. <match url=“^(.*)$” ignoreCase=“false” />
  8. <conditions logicalGrouping=“MatchAll”>
  9. <add input=“{HTTP_FROM_HTTPS}” pattern=“^on$” negate=“true” />
  10. <add input=“{HTTP_HOST}” pattern=“^m.idiyrom.com$” negate=“true” />
  11. </conditions>
  12. <action type=“Redirect” url=“https://www.idiyrom.com/{R:1}” redirectType=“Permanent” />
  13. </rule>
  14. </rules>
  15. </rewrite>
  16. </system.webServer>
  17. </configuration>
赞(0)
声明:本站发布的内容(图片、视频和文字)以原创、转载和分享网络内容为主,若涉及侵权请及时告知,将会在第一时间删除。本站原创内容未经允许不得转载:西数超哥博客 » web.config规则http跳转到https规则