2008年1月23日 星期三

Apache http自動轉https(轉載)

 由於公司之前使用 HTTP 提供某個服務給全公司,但後來考慮到安全性問題希望改用 HTTPS,但已經公佈的 HTTP 網址,不希望再通知請 User 更改習慣,於是想到 Apache 應該可以將 User 輸入的 HTTP 自動轉為 HTTPS,於是找到下面這篇文章「Apache http自動轉https」轉載於”a-wei's X garden”部落格,因為覺得很實用,所以就收錄進來,並註明出處。

引述:apache mod_rewrite 這個模組 .. 好用的不得了 … 詳細的用法,老實說 .. 呵呵 .. 也沒研究的那麼透徹..
此筆記,主要是紀錄 apache 如何自動的從 http 非加密模式,轉移到 https 的加密法 .
httpd.conf
一、整個網站轉移
在 VirtualServer 內的 Directory
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R]
二、某個目錄做自動轉移
在該目錄內

RewriteEngine on
RewriteBase /folder
RewriteCond %{SERVER_PORT} !^443$
#RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R]
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

這樣就會自動轉移了
另外寫在網站目錄內的 .htaccess 也是可以的


沒有留言:

張貼留言