Apache版本如(rú)果需要整站(zhàn)跳(tiào)轉,則在網站(zhàn)的配置文件的标簽内,鍵入以下(xià)内容: RewriteEngine on RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R]
如(rú)果對某個(gè)目錄做強制跳(tiào)轉,則使用以下(xià)代碼: RewriteEngine on RewriteBase /yourfolder RewriteCond %{SERVER_PORT} !^443$ #RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R] RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
Nginx版本在配置80端口的文件裏面,寫入以下(xià)内容即可。 server { listen 80; server_name localhost; rewrite ^(.*)$ https://$host$1 permanent; location / { root html; index index.html index.htm; }
PHP頁面跳(tiào)轉:添加在網站(zhàn)php頁面内 if ($_SERVER["HTTPS"] <> "on") { $xredir="https://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; header("Location: ".$xredir); }
單獨頁面通用代碼段:較适合指定某一(yī)個(gè)子(zǐ)頁單獨https 在需要強制為(wèi)https的頁面上(shàng)加入以下(xià)代碼進行處理(lǐ)http—>https <script language="JavaScript" type="text/JavaScript"> function redirect() { var loc = location.href.split(':'); if(loc[0]=='http') { location.href='https:'+loc[1]; } } onload=redirect </script> |