纵有疾风起
人生不言弃

http重定向https

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

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!

未经允许不得转载:起风网 » http重定向https
分享到: 生成海报

评论 抢沙发

评论前必须登录!

立即登录