JavaScript :始终重定向到 HTTPS
JavaScript : Always Redirect To HTTPS
所以我有这个网站,我希望当有人在网上浏览它时,它总是重定向到 HTTPS。我想使用 JavaScript
这段代码是否正确?
if(window.location.protocol != "https:") {
var currentURL = window.location.href;
window.location.replace("https" + currentURL.substring(4));
}
我还是个菜鸟。请帮帮我:)
试试这个
if (window.location.protocol == "http:") {
var mainurl = window.location.href.substr(5);
window.location = "https:" + mainurl;
}
相关文章:
- 通过javascript重定向html传递php变量
- web配置http到https重定向异常
- 在Chrome扩展中使用PAC文件重定向HTTPS请求似乎失败了
- 通过端口更改自动重定向到 https
- 检查用户提供的网址是否会重定向到 https 或 http
- htaccess - 将单个 HTML 页面重定向到 HTTPS
- 将所有http请求重定向到帆js中的https
- 将网站重定向到HTTPS,重试次数有限
- 防止在服务工作者中阻止从https重定向到http
- Express 4– 将所有路由的HTTP重定向到HTTPS
- 正在加载可能重定向到HTTP的HTTPS图像url
- location.href未重定向到https://urls
- 用户登录后将所有网页重定向到HTTPS
- 重定向到安全服务器(https)
- 什么是最'犹太教'或& # 39;正确# 39;实现HTTPS重定向的方法
- 将nodejsexpress静态请求重定向到https
- 表达4.X重定向HTTP到https
- 只使用ajax进行登录https://,以避免重定向时出现警告
- JavaScript :始终重定向到 HTTPS
- Youtube重定向http到https,并使用flash播放器而不是HTML5