iis7以上自动跳转到HTTPS

IIS7需要先确认是否安装 “URL 重写” 或者 “URL Rewrite” 模块 , 如果您已经安装可以跳过

2.0版重写模块x64】 - 【2.0版重写模块x32

2.1版重写模块x64】 - 【2.1版重写模块x32

将下面全部代码保存成web.config文件,存放到空间的web目录下即可。再次提醒:里面的网址记得改成你自己的网站,别懒得只会copy!

HTTP 跳转 HTTPS:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<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://{HTTP_HOST}/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

同时将不带www跳转向带www的https规则

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="www" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^ip110\.com$" />
</conditions>
<action type="Redirect" url="https://www.ip110.com/{R:0}" />
</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://{HTTP_HOST}/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>