如果需要整站跳轉,則在網站的配置文件的标簽内,鍵河又入以下内容:
RewriteEngine on
RewriteCond %{SERVER_PORT} !^44這討3$
RewriteRule ^(.*)?$ htt自話ps://%{SERVER_NAME}/$1 [L,R]
如果對(duì)某個目錄做強制跳轉,則使用以下代碼:
RewriteEngine on
RewriteBase /yourfolder
RewriteCond %{SER答雪VER_PORT} !^443$森動
#RewriteRule ^(.*)?$ https:/答看/%{SERVER_NAME}/$1 [L,R]
RewriteRule ^.*$ http去年s://%{SERVER_NAME}%{REQUEST_URI} 好見[L,R]
在配置80端口的文件裡(lǐ)面(miàn)去森,寫入以下内容即可。
server {
listen 80;
server_name localhost;
rewrite ^(.*)$ https://$host$1 perm子男anent;
location / {
root html;
index index.html index.htm;
}
PHP頁面(miàn)跳轉:添加在網站php頁面(mi業醫àn)内
if ($_SERVER["HTTPS&quo外們t;] <> "笑外on")
{
$xredir="https://".$對光_SERVER["SERVER_NAME&quo書匠t;].$_SERVER["REQUEST_URI"藍廠;];
header("Location: ".$xr關老edir);
}
單獨頁面(miàn)通用代碼段:較适合指定某一個子頁單獨https 在著老需要強制為https的頁面(miàn)上加入以下代碼進(jìn)行處微生理http—>https
<script language="JavaScript&qu空可ot; type="text/JavaScript男和">
function redirect()
{
var loc = locatio秒訊n.href.split(':');
if(loc[0]=='http')
{
location.href='https:'+loc[北新1];
}
}
onload=redirect
</script>
0592-8833123
0592-8399399