最近在架服務時,突然蹦出個強制都走 https 的念頭,找了一下果然可以用 rewrite rules 來解決 :P
$ sudo a2ensite default-ssl
$ sudo a2enmode rewrite ssl
$ sudo vim default
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
</Directory>
沒有留言:
張貼留言