下面是我用过的两种简单的方法:
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!
还没有人抢沙发呢~