如果我使用:
<meta http-equiv="REFRESH" content="0;url=https://www.the-domain-you-want-to-redirect-to.com/index.html">
在HTML代码中,它将无休止地循环并刷新https页面.
如何将用户重定向到https?[关于一个index.html文件]
如果他们只使用"http",我需要在"index.html"的html代码中重新定位它们?
谢谢
Bra*_*tie 41
var loc = window.location.href+'';
if (loc.indexOf('http://')==0){
window.location.href = loc.replace('http://','https://');
}
Run Code Online (Sandbox Code Playgroud)
也许?只要你不介意一个小的javascript依赖.
希望这可以帮助
<html>
<head>
<title>
Redirecting...</title></head>
<script language="JavaScript">
function redirectHttpToHttps()
{
var httpURL= window.location.hostname + window.location.pathname + window.location.search;
var httpsURL= "https://" + httpURL;
window.location = httpsURL;
}
redirectHttpToHttps();
</script>
<body>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)