Apache Force SSL on vhost

Apache Force SSL on vhost

Howto configure Apache to redirect all http requests to the SSL version of the site.

Edit your htaccess (or server conf file) to look like this one :

<Files *.ini>
Order Allow,Deny
Deny from all
</Files>

RewriteEngine on
RewriteBase /

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

For thoses of you who don’t know about RewriteCond, the first one checks the server port used to connect. If it’s not 443 (default HTTPS port), it redirects all request to the same https vhost and URI.

Reference

  • https://trac.usvn.info/wiki/Documentation/HTTPSAccess