IIS 使用 web.config 实现从 http 自动301跳转到 https 的方法

 现在很多网站为了安全,开启了 SSL 连接,那么开启 SSL 连接之后,如何将对应的 http 访问自动跳转到 https 上呢?之前介绍了 IIS 用 web.config 做域名的301跳转的方法,同样使用 IIS 可以用 web.config 实现 http 网址自动301跳转到 https 网址。

上一篇文章是利用访问域名的方式进行301跳转,也就是判断访客的域名,然后进行跳转。可是 http 和 https 访问的网址是一样的,这样上面这篇文章的 web.config 代码就不能使用了。

其实换个思路就清楚了,那么判断域名不行了,我们是不是可以直接判断 https 状态呢?非 https 状态自动跳转到 https 对应网址。

web.config 代码如下:

  

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
 <system.webServer>
  <rewrite>
   <rules>
    <rule name="HTTPS iCoA" stopProcessing="true">
     <match url=".*" />
     <conditions>
      <add input="{HTTPS}" pattern="^off" />
     </conditions>
     <action type="Redirect" url="http://www.yuanzhumuban.cc/{R:0}" redirectType="Permanent" />
    </rule>
   </rules>
  </rewrite>
 </system.webServer>
</configuration>

  

猜你喜欢

转载自www.cnblogs.com/68xi/p/11518979.html