IIS http強制重定向到https

首先安裝 URL Rewrite 模塊 ,下載網址 

http://www.iis.net/downloads/microsoft/url-rewrite

安裝完成後, 在網站根目錄下建立web.config 文件,文件內容如下 

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="HTTP/S to HTTPS Redirect" enabled="true" stopProcessing="true">
        <match url="(.*)" />
        <conditions logicalGrouping="MatchAny">
          <add input="{SERVER_PORT_SECURE}" pattern="^0$" />
        </conditions>
        <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>


即可實現每次用戶只要在瀏覽器打開www.abc.com 即自動跳轉到https://www.abc.com

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章