您所在的位置:首页 > SSL证书
IIS 不用URL重定向搞定http强制跳转至https
发布时间:2016/11/23 22:17:17 浏览:122打印字号:大中小
思路:既然选择 要求SSL 提示403错误,那为什么不在403错误页面加上强制js由http到https勒?
1、安装证书(不是本文重点,烦请搜索引擎自行查找)
2、“编辑绑定” --> "添加" --> "https" and 选择"证书" (其他不需要修改)
3、“SSL设置” --> 勾上“要求SSL”+ 客户证书 "忽略"
4、 现在直接访问80会提示 403错误
5、找到 403错误页面,我的在 (C:\inetpub\custerr\zh-CN\403.htm),编辑打开,在<head>标签中加入
<script type="text/javascript"> var url=window.location.href; url=url.replace("http:","https:") window.location.replace(url);</script>
6、输入不带https就会先跳转到403错误页面,在跳转到https//{HTTP_HOST}/xxx 页面啦!
补充使用 js 强制 http 到 https
<script type="text/javascript"> var targetProtocol = "https:"; if (window.location.protocol != targetProtocol) window.location.href = targetProtocol + window.location.href.substring(window.location.protocol.length);</script>