#### http 如何强转为 https,几行JS 代码就搞定了,网上说得很难一样!还有如何自定义 404页面,一起讲了;
在 网站入口 html 的 js 文件中写入这几行代码就OK了!,网站需要替换成自己的,当然你得开通了 https;关于怎么开通 HTTPS 请关注我个人网站
动向,会在 https://seeweekend.com/git 中公开方法和源码;也可以通过 发送 邮箱 ceo@seeweekend.com ;
```
function() {
var gethref = window.location.href.split("://")
if("https" != gethref[0]) {
self.location = "https://seeweekend.com/Web/main.html"
}}()
```
这是我的网站,可以作为案例测试:
- [x] 可在浏览器输入: http://seeweekend.com
- [x] 可在浏览器输入: seeweekend.com
- [x] 可在浏览器输入: www.seeweekend.com
无论是输入 http,还是直接输入域名,都会直接跳到 https://seeweekend.com 安全连接;
#####
#### 还有就是如何自定主404 页面,而且 如何让 404 页面也显示为 https 的安全连接问题:
比如我随便输入一个 不存在的页面 :https://seeweekend.com/hao.html
就会直接跳转到我定义好的 404页面了:
https://seeweekend.com/404.htm
#### 这里我只讲 TOMCAT 的配置方法:
在 网站入口 html 的 js 文件中写入这几行代码就OK了!,网站需要替换成自己的,当然你得开通了 https;关于怎么开通 HTTPS 请关注我个人网站
动向,会在 https://seeweekend.com/git 中公开方法和源码;也可以通过 发送 邮箱 ceo@seeweekend.com ;
```
function() {
var gethref = window.location.href.split("://")
if("https" != gethref[0]) {
self.location = "https://seeweekend.com/Web/main.html"
}}()
```
这是我的网站,可以作为案例测试:
- [x] 可在浏览器输入: http://seeweekend.com
- [x] 可在浏览器输入: seeweekend.com
- [x] 可在浏览器输入: www.seeweekend.com
无论是输入 http,还是直接输入域名,都会直接跳到 https://seeweekend.com 安全连接;
#####
#### 还有就是如何自定主404 页面,而且 如何让 404 页面也显示为 https 的安全连接问题:
比如我随便输入一个 不存在的页面 :https://seeweekend.com/hao.html
就会直接跳转到我定义好的 404页面了:
https://seeweekend.com/404.htm
#### 这里我只讲 TOMCAT 的配置方法:
网上讲了很多方法,其实都是不能真正实现这种效果的,其关键是 tomcat 的 root 文件配置;我就直接把这个文上传到了我的 git 上了;你可以上去下载下来,用到自己项目中,就可以看到跟我的网页一样的效果了,当然我也有些漏洞但都是很简单就可以处理的;
源码地址: https://seeweekend.com/git/docs/tomcat404ROOT.git