提問三步曲: 提問先看教程/FAQ索引(wdcp,wdcp_v3,一鍵包)及搜索,會讓你更快解決問題
1 提供詳細,如系統版本,wdcp版本,軟件版本等及錯誤的詳細信息,貼上論壇或截圖發(fā)論壇
2 做過哪些操作或改動設置等
溫馨提示:信息不詳,很可能會沒人理你!論壇有教程說明的,也可能沒人理!因為,你懂的
[教程] 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的方法較多,以上僅供參考。 |