Apache HTTPS only vhosts

If you want to serve your domain only over HTTPS and redirect all requests made to standard HTTP port to HTTPS than this configuration might be helpful:

1
2
3
4
5
6
7
8
9
10
11
12
13
<VirtualHost *:80>
        ServerName www.example.com
        RewriteEngine On
        RewriteCond %{HTTP_HOST}        (.*)
        RewriteRule (.*) https://%1$1 [R=301,L]
</VirtualHost>
 
<VirtualHost *:443>
        ServerName www.example.com
 
        // other vhost configuration follows
        ...
</VirtualHost>

Leave a Reply