document.writeln('');
LAMP或者LNMP集成環(huán)境跳轉(zhuǎn):
首先在網(wǎng)站根目錄下創(chuàng)建.htaccess文件,如果目錄下已經(jīng)有.htaccess文件,則用vi或者其他編輯器打開,在最下面添加寫入如下語句即可
RewriteEngine onRewriteBase /RewriteCond %{SERVER_PORT} !^443$RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]RewriteEngine on RewriteBase / RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]RewriteEngine onRewriteBase /RewriteCond %{SERVER_PORT} !^443$RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
Apache服務器:
如果需要整站跳轉(zhuǎn),則在網(wǎng)站的配置文件的<Directory>標簽內(nèi),鍵入以下內(nèi)容:
RewriteEngine onRewriteCond %{SERVER_PORT} !^443$RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R]RewriteEngine on RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R]RewriteEngine onRewriteCond %{SERVER_PORT} !^443$RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R]
如果對某個目錄做https強制跳轉(zhuǎn),則復制以下代碼:
RewriteEngine onRewriteBase /yourfolderRewriteCond %{SERVER_PORT} !^443$#RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R]RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]RewriteEngine on RewriteBase /yourfolder RewriteCond %{SERVER_PORT} !^443$ #RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R] RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]RewriteEngine onRewriteBase /yourfolderRewriteCond %{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 <a target="_blank" href="https://123vo.cn/tag/31.html" title="View all posts in html">html</a>;index index.html index.htm;}server { listen 80; server_name localhost; rewrite ^(.*)$ https://$host$1 permanent; location / { root <a target="_blank" title="View all posts in html">html</a>; index index.html index.htm; }server {listen80;server_namelocalhost;rewrite ^(.*)$ https://$host$1 permanent;location / {roothtml;indexindex.html index.htm;}
JS跳轉(zhuǎn):
以下方法較適合指定某一個子頁單獨https,如果網(wǎng)頁定義了top或者boot文件,可以在這個文件里面加入;
在需要強制為https的頁面上加入以下代碼進行處理http–>https
<script type="text/<a target="_blank" href="https://123vo.cn/tag/35.html" title="View all posts in javascript">javascript</a>">var url = window.location.href;if (url.indexOf("https") < 0) {url = url.replace("http:", "https:");window.location.replace(url);}</script><script type="text/<a target="_blank" title="View all posts in javascript">javascript</a>"> var url = window.location.href; if (url.indexOf("https") < 0) { url = url.replace("http:", "https:"); window.location.replace(url); } </script><script type="text/javascript">var url = window.location.href;if (url.indexOf("https") < 0) {url = url.replace("http:", "https:");window.location.replace(url);}</script>
PHP跳轉(zhuǎn):
添加在網(wǎng)站php頁面內(nèi)
<?phpif ($_SERVER["HTTPS"] <> "on"){$xredir = "https://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];header("Location: ".$xredir);}?><?php if ($_SERVER["HTTPS"] <> "on") { $xredir = "https://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; header("Location: ".$xredir); } ?><?php if ($_SERVER["HTTPS"] <> "on"){$xredir = "https://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];header("Location: ".$xredir);}?>