Apache版本如果需要整站跳轉(zhuǎn),則在網(wǎng)站的配置文件的標(biāo)簽內(nèi),鍵入以下內(nèi)容: RewriteEngine on RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R]
如果對某個(gè)目錄做強(qiáng)制跳轉(zhuǎn),則使用以下代碼: 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端口的文件里面,寫入以下內(nèi)容即可。 server { listen 80; server_name localhost; rewrite ^(.*)$ https://$host$1 permanent; location / { root html; index index.html index.htm; }
PHP頁面跳轉(zhuǎn):添加在網(wǎng)站php頁面內(nèi) if ($_SERVER["HTTPS"] <> "on") { $xredir="https://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; header("Location: ".$xredir); }
單獨(dú)頁面通用代碼段:較適合指定某一個(gè)子頁單獨(dú)https 在需要強(qiáng)制為https的頁面上加入以下代碼進(jìn)行處理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> |