WDlinux官方论坛's Archiver

Miker 发表于 2016-3-24 09:20

WDCP实现http跳转https教程方法

[i=s] 本帖最后由 Miker 于 2016-12-15 15:37 编辑 [/i]

APache 版本

如果需要整站跳转,则在网站的配置文件的<Directory>标签内,键入以下内容:[code]RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R][/code]如果对某个目录做https强制跳转,则复制以下代码:[code]RewriteEngine on
RewriteBase /yourfolder
RewriteCond %{SERVER_PORT} !^443$
#RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R]
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R][/code]如果只需要对某个网页进行https跳转,可以使用redirect 301来做跳转!redirect 301  /你的网页 https://你的主机+网页

Nginx版本

在配置80端口的文件里面,写入以下内容即可。[code]server {
        listen       80;
        server_name  localhost;
       rewrite ^(.*)$ https://$host$1 permanent;   

        location / {
            root   html;
            index  index.html index.htm;
        }[/code]TOMCAT 版本

1、在conf目录下的server.xml文件中找到以下配置,修改redirectPort参数值为"443",默认是“8443”.[code]<Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="443" />[/code]复制代码
2、在conf目录下的web.xml文件内容<web-app>……</web-app>中增加以下配置。

复制代码

单独页面通用代码段:以下方法较适合指定某一个子页单独https
在需要强制为https的页面上加入以下代码进行处理http-->https[code]<script type="text/javascript">
        var url = window.location.href;
        if (url.indexOf("https") < 0) {
        url = url.replace("http:", "https:");
        window.location.replace(url);
        }
</script>[/code][code]<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>[/code]在需要强制为http的页面上加入以下代码进行处理
https-->http[code]<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> [/code]PHP页面跳转:添加在网站php页面内[code]if ($_SERVER["HTTPS"] <> "on")
{
$xredir="https://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
header("Location: ".$xredir);
}[/code]http跳转https的方法较多,以上仅供参考。

youqingxiaozhu 发表于 2016-3-24 09:42

不需要装ssl证书?只需要插入这段代码就可以了?

Miker 发表于 2016-3-28 11:43

[b]回复 [url=http://www.wdlinux.cn/bbs/redirect.php?goto=findpost&pid=86099&ptid=52725]2#[/url] [i]youqingxiaozhu[/i] [/b]

需要安装证书的亲

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

[b]回复 [url=http://www.wdlinux.cn/bbs/redirect.php?goto=findpost&pid=86098&ptid=52725]1#[/url] [i]Miker[/i] [/b]


   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

[b]回复 [url=http://www.wdlinux.cn/bbs/redirect.php?goto=findpost&pid=109462&ptid=52725]9#[/url] [i]xyz007wjm[/i] [/b]


    目前最新面板已经支持自带强制跳转打开即可

Miker 发表于 2018-11-30 16:54

[b]回复 [url=http://www.wdlinux.cn/bbs/redirect.php?goto=findpost&pid=109458&ptid=52725]8#[/url] [i]宋大光[/i] [/b]


    删除缓存开启https即可

页: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.