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
  • Michel Racic avatar
    About Michel Racic
    I’m a coding and technology freak. I finished once my bachelor of engineering in computer science or on german “Dipl. Ing.” and currently I’m mostly coding in Java as main language besides some stuff in C, C++, C#, HTML, JS, … - In my day job I work as a Software Engineer in Test and deal with all kind of Software from Native over Web into Mainframe where I use existing tools or write my own testing apps or libraries and the Frameworks around that they can be used in the most efficient way.
    comments powered by Disqus