所以我有这个网站,我希望它总是在任何人在网上浏览时重定向到HTTPS。我想使用JavaScript
这段代码是否正确?
if(window.location.protocol != "https:") {
var currentURL = window.location.href;
window.location.replace("https" + currentURL.substring(4));
}
我还是个菜鸟。请帮帮我:)。
答案 0 :(得分:-1)
试试这个
if (window.location.protocol == "http:") {
var mainurl = window.location.href.substr(5);
window.location = "https:" + mainurl;
}