http重定向https

版权声明:本文为博主原创文章,转载请注明原文出处。 https://blog.csdn.net/qq_41139830/article/details/82320151

下面是我用过的两种简单的方法:

1、meta标签

<meta http-equiv="refresh" content="0;url=https://liuyibo.top" />

其中 http-equiv="refresh"会让网页刷新。content中的0,意思是网页0秒刷新,可以改成其他数字,比如:2,就是延迟2秒刷新url 就是你网页的https的地址啦。

2、用js实现强制跳转

<script>
    (function () {
      var url = window.location.href;        //获取网页的url

      if (url.match('http')) {               //匹配到是http访问
        url = url.replace('http', 'https');  //替换url中的http为https
        window.location.replace(url);        //新页面取代旧页面
      }
    })();
</script>

将上述代码加入你的网页head标签里就行了。

END!

猜你喜欢

转载自blog.csdn.net/qq_41139830/article/details/82320151