标题:
[教程]
WDCP实现http跳转https教程方法
[打印本页]
作者:
Miker
时间:
2016-3-24 09:20
标题:
WDCP实现http跳转https教程方法
本帖最后由 Miker 于 2016-12-15 15:37 编辑
APache 版本
如果需要整站跳转,则在网站的配置文件的<Directory>标签内,键入以下内容:
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R]
复制代码
如果对某个目录做https强制跳转,则复制以下代码:
RewriteEngine on
RewriteBase /yourfolder
RewriteCond %{SERVER_PORT} !^443$
#RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R]
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
复制代码
如果只需要对某个网页进行https跳转,可以使用redirect 301来做跳转!redirect 301 /你的网页 https://你的主机+网页
Nginx版本
在配置80端口的文件里面,写入以下内容即可。
server {
listen 80;
server_name localhost;
rewrite ^(.*)$ https://$host$1 permanent;
location / {
root html;
index index.html index.htm;
}
复制代码
TOMCAT 版本
1、在conf目录下的server.xml文件中找到以下配置,修改redirectPort参数值为"443",默认是“8443”.
<Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="443" />
复制代码
复制代码
2、在conf目录下的web.xml文件内容<web-app>……</web-app>中增加以下配置。
复制代码
单独页面通用代码段:以下方法较适合指定某一个子页单独https
在需要强制为https的页面上加入以下代码进行处理http-->https
<script type="text/javascript">
var url = window.location.href;
if (url.indexOf("https") < 0) {
url = url.replace("http:", "https:");
window.location.replace(url);
}
</script>
复制代码
<web-app>
.........
<security-constraint>
<web-resource-collection >
<web-resource-name >SSL</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
</web-app>
复制代码
在需要强制为http的页面上加入以下代码进行处理
https-->http
<script language="JavaScript" type="text/JavaScript">
function redirect()
{
var loc = location.href.split(':');
if(loc[0]=='https')
{
location.href='http:'+loc[1];
}
}
onload=redirect
</script>
复制代码
PHP页面跳转:添加在网站php页面内
if ($_SERVER["HTTPS"] <> "on")
{
$xredir="https://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
header("Location: ".$xredir);
}
复制代码
http跳转https的方法较多,以上仅供参考。
作者:
youqingxiaozhu
时间:
2016-3-24 09:42
不需要装ssl证书?只需要插入这段代码就可以了?
作者:
Miker
时间:
2016-3-28 11:43
回复
2#
youqingxiaozhu
需要安装证书的亲
作者:
cdd311
时间:
2016-12-14 17:52
有其他解决方案么? 为什么通过rewrite会出现 死循环?
作者:
52jbj
时间:
2017-1-15 16:22
直接访问https://www.52jbj.com/soft/
作者:
else
时间:
2017-3-13 11:35
测有做过测试吧!
作者:
else
时间:
2017-3-13 11:37
n+a是用88商品去处理php
像我的都是php
所以,就是直接
RewriteEngine on
RewriteCond %{SERVER_PORT} ^88$
RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R]
调用了88
作者:
宋大光
时间:
2018-11-29 11:31
3.2.21开启强制启用还是跳转不了,怎么回事啊?
作者:
xyz007wjm
时间:
2018-11-30 07:58
回复
1#
Miker
DZ 3.4 添加代码后是这样的,死循环?https://www.honghe365.com/public_html/public_html/public_html/public_html/public_html/public_html/public_html/public_html/public_html/public_html/public_html/public_html/public_html/public_html/public_html/public_html/public_html/public_html/public_html/
作者:
Miker
时间:
2018-11-30 16:54
回复
9#
xyz007wjm
目前最新面板已经支持自带强制跳转打开即可
作者:
Miker
时间:
2018-11-30 16:54
回复
8#
宋大光
删除缓存开启https即可
欢迎光临 WDlinux官方论坛 (http://www.wdlinux.cn/bbs/)
Powered by Discuz! 7.2