http to https, 全站改为https

网站环境为window 2012 server + IIS8.5, SSL为godaddy网站的付费证书。IIS配置好SSL后, 只需要在网站的web.config写上配置代码即可。

  • 以下为web.config 的配置代码

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    <system.webServer>
    <rewrite>
    <rules>
    <rule name="Redirect to https" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
    <add input="{HTTPS}" pattern="^OFF$" />
    <add input="{HTTPS_HOST}" pattern="^(localhost)" negate="true" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}:443/{R:1}" redirectType="SeeOther" />
    </rule>
    </rules>
    </rewrite>
    </system.webServer>
  • BTW: IIS 需要安装URL Rewrite 模块,如下图红线圈所示, 如果没有安装,配置将无效