天天看點

Apache網站安裝ssl證書後實作http自動跳轉為https

APache 伺服器中

如果需要整站跳轉,則在網站的配置檔案.htaccess的标簽内,鍵入以下内容:

RewriteEngine on

RewriteCond %{SERVER_PORT} !^443$

RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R]

如果對某個目錄做https強制跳轉,則複制以下代碼:

RewriteEngine on

RewriteBase /yourfolder

RewriteCond %{SERVER_PORT} !^443$

#RewriteRule ^(.*)?$ https://%{SERVER_NAME}/ 1 [ L , R ] R e w r i t e R u l e . ∗ 1 [L,R] RewriteRule ^.* 1[L,R]RewriteRule.∗ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

如果隻需要對某個網頁進行https跳轉,可以使用redirect 301來做跳轉!redirect 301 你的網頁 https://你的主機+網頁

繼續閱讀