网站配置好SSL证书后,面临一个问题就是,原来收录以及链接的http如何让它变更为https?

在IIS7/7.5环境中,有这么几种方法:

方法一:使用伪静态跳转(303) web.config

1.下载安装URL重写模块:Microsoft URL Rewrite Module

2.编辑网站根目录下的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>

方法二:利用403错误页跳转

1.在IIS站点里面,选择 “SSL设置” --> 勾上“要求SSL”+ 客户证书 "忽略";

2.找到 403错误页面,我的在 (C:\inetpub\custerr\zh-CN\403.htm),编辑打开,在标签中加入

<script type="text/javascript">  
    var url=window.location.href;  
    url=url.replace("http:","https:")  
    window.location.replace(url);
</script>

方法三:使用JS脚本判断HTTP及HTTPS

在需要跳转的页面头部添加:

<script type="text/javascript">
  var targetProtocol = "https:";
  if (window.location.protocol != targetProtocol)
  window.location.href = targetProtocol +
  window.location.href.substring(window.location.protocol.length);
</script>

总结:

方法一、方法二适用于整站跳转,这里推荐使用方法一,因为是303跳转,对收录、权重无影响;

方法三适用于部分页面跳转,比较灵活。

因为如果https页面加载了其它http页面的资源,例如CSS/JS/图片等等,就会报错,页面异常等。

关于ssl、IIS配置HTTPS等方法及故障,请浏览本人前面的文章。

标签: iis, https, ssl

添加新评论