I needed this for something as simple as redirecting all http
traffic from the default apache home page on my server to one served over https
.
Since I'm still quite green when it comes to configuring apache, I prefer to avoid using mod_rewrite
directly and instead went for something simpler like this:
<VirtualHost *:80>
<Location "/">
Redirect permanent "https://%{HTTP_HOST}%{REQUEST_URI}"
</Location>
</VirtualHost>
<VirtualHost *:443>
DocumentRoot "/var/www/html"
SSLEngine on
...
</VirtualHost>
I like this because it allowed me to use apache variables and that way I didn't have to specify the actual host name since it's just an IP address without an associated domain name.
References: https://stackoverflow.com/a/40291044/2089675