將原先已公佈的 HTTP 網址轉為 HTTPS,這樣就不會造成使用者在輸入 HTTP 找不到網頁或更改使用習慣的問題。
修改 /etc/httpd/conf/httpd.conf 設定檔:
LoadModule rewrite_module modules/mod_rewrite.so //找到這行,註解#拿掉(Linux預設是無註解,但在windows就要自行拿掉)
<Directory "/var/www/html/test/">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
//加入內容,亦可以加入到 <VirtualHost IP:Port>...</VirtualHost>,擇一使用。
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]
加入內容結束
</Directory>
NameVirtualHost 192.168.1.2:80
Listen 192.168.1.2:80
<VirtualHost 192.168.1.2:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /var/www/html/test/
ServerName www.test.com.tw
ServerAlias www.test.com.tw
ErrorLog logs/www.test.com.tw-error_log
CustomLog logs/www.test.com.tw-access_log common
DirectoryIndex index.php index.html index.htm
//加入內容,如果已在 <Directory>...</Directory> 加入,那這裡不能加入,擇一使用。
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R]
//加入內容結束
</VirtualHost>
在網站目錄加入 /var/www/html/website/.htaccess 檔案
RewriteEngine on
RewriteBase /folder
RewriteCond %{SERVER_PORT} !^443$
#RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R]
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
請先 登入 以發表留言。