最近在架服務時,突然蹦出個強制都走 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>


, ,

changyy 發表在 痞客邦 PIXNET 留言(0) 人氣()