有没有办法检测HTTP或HTTPS,然后强制使用HTTPS与JavaScript?
我有一些代码用于检测HTTP或HTTPS,但我不能强制它使用https:.
我正在使用window.location.protocol属性来设置站点的任何内容,https:然后刷新页面以希望重新加载加载到浏览器中的新https'ed URL.
if (window.location.protocol != "https:") {
window.location.protocol = "https:";
window.location.reload();
}
Run Code Online (Sandbox Code Playgroud) 我想将用户从我的 http 网站重定向到 https 网站,是否有像元或 JavaScript 或 html 这样的网站来执行此操作,我的网站有一个 http 服务器以及一个安全版本。