现在我们说说iis7设置http跳转https,因为还是有很多人在用iis服务器。首先要先安装url rewrite module,到这里去下载http://www.microsoft.com/en-us/download/details.aspx?id=7435,以administrator管理员的身份去安装这个模块,安装完以后需要重启一下IIS,你就会看到URL Rewrite已经出现了,如下图所示
第二步我们就可以开始设置跳转了,比如把a.com跳到www.a.com,在a网站的根目录下有一个web.config文件,这个就是设置跳转规则的文件
代码语言:javascript复制<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="WWW Redirect" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^a.com$" />
</conditions>
<action type="Redirect" url="http://www.a.com/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
如果要把b.com跳到www.a.com
代码语言:javascript复制<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="WWW Redirect" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^b.com$" />
</conditions>
<action type="Redirect" url="http://www.a.com/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
重点来了,如果有多个站点(包含www.a.com),并且这些站点都要跳转到https://www.a.com,要如何操作呢?首先多站点用|线分割,http跳https需要另外设定一个rule规则,整合代码如下
代码语言:javascript复制<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="WWW Redirect" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^a.com|b.com$" />
</conditions>
<action type="Redirect" url="https://www.a.com/{R:0}" redirectType="Permanent" />
</rule>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Found" url="https://www.a.com" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>