我們可以用Apache的.htaccess的重定向規(guī)則來實現http強制跳轉到https訪問網站。( 重要提示:必須將代碼放到.htaccess文件內容的最前面,以保證重定向優(yōu)先權。)
代碼如下:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://xpsss.com/$1 [R,L]
或者
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://xpsss.com/$1 [R=301,L]
又或者
RewriteEngine on
RewriteBase /
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
注意:如果是在子目錄,可以用
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} subfolder
RewriteRule ^(.*)$ https://xpsss.com/subfolder [R,L]
將以上代碼復制到.htaccess中即可。
以上這篇Apache使用 .htaccess 來實現強制https訪問的方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
您可能感興趣的文章:- apache https配置詳細步驟講解
- Apache mod_rewrite實現HTTP和HTTPS重定向跳轉
- apache設置自動將http跳轉到https的方法
- 阿里云服務器apache配置SSL證書成功開啟Https(記錄趟過的各種坑)
- Apache由http自動跳轉到https的多種方法
- apache中使用mod_gnutls模塊實現多個SSL站點配置(多個HTTPS協(xié)議的虛擬主機)
- 詳解在Ubuntu上的Apache配置SSL(https證書)的正確姿勢
- IIS與APACHE實現HTTP重定向到HTTPS
- Linux環(huán)境下Apache開啟https服務的方法詳解