IIS7的http 做301重定向到https
我們的香港空間部分是windows下的IIS平臺(tái),一些用戶安裝了SSL https證書后,不會(huì)控制301跳轉(zhuǎn),下面直接貼出代碼,根據(jù)需要把代碼放到web.config文件里即可。
http跳轉(zhuǎn)到https
這個(gè)代碼段是http重定向到https, 注意,要放在<rules>和</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>
http跳轉(zhuǎn)到https
提醒:里面的網(wǎng)址記得改成你自己的網(wǎng)站,別懶得只會(huì)copy!
這個(gè)代碼段是無3w重定向到有3w域名, 注意,要放在<rules>和</rules>之間。
<rule name="www" stopProcessing="true"> <match url=".*" /> <conditions> <add input="{HTTP_HOST}" pattern="^ip110\.com$" /> </conditions> <action type="Redirect" url="http://www.yasamdan.net/{R:0}" /> </rule>
完整的web.config代碼
下面代碼包含了,無3w網(wǎng)址,跳轉(zhuǎn)到有3w網(wǎng)址; 以及, http全部跳轉(zhuǎn)到https
當(dāng)然了,知道大家懶,已經(jīng)將兩份整合到一起,將下面全部代碼保存成web.config文件,存放到空間的web目錄下即可。再次提醒:里面的網(wǎng)址記得改成你自己的網(wǎng)站,別懶得只會(huì)copy!
<?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="http://www.yasamdan.net/{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>