1. 程式人生 > >IIS (安裝SSL證書後) 實現 HTTP 自動跳轉到 HTTPS

IIS (安裝SSL證書後) 實現 HTTP 自動跳轉到 HTTPS

IIS 裡 安裝好 SSL 證書後,如何實現 在瀏覽器裡錄入 http://www.xxx.com,會自動跳轉到 https://www.xxx.com 呢。

首先,下載並安裝 IIS 擴充套件: URL重寫(URL Rewrite)擴充套件

URL重寫擴充套件下載地址: https://www.iis.net/downloads/microsoft/url-rewrite

 

其次,修改 web.config 檔案:

<?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>

 

最後,重啟網站 或重啟 IIS。在瀏覽器裡錄入:http://www.xxx.com,會自動跳轉到 https://www.xxx.com