This Apache reference page and this wiki clearly states that to achieve simple http to https redirects, mod_alias
should be used instead of the more expensive mod_rewrite
.
I have an Apache virtualhost which uses a wildcard to match multiple subdomains. I need all these subdomains redirected to their corresponding https counterparts. Currently, I am using the following (with mod_rewrite):
<VirtualHost *:80>
ServerName lvh.me
ServerAlias *.lvh.me
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]
</VirtualHost>
I tried the following, but it did not work.
<VirtualHost *:80>
ServerName lvh.me
ServerAlias *.lvh.me
Redirect temp / https://%{HTTP_HOST}/
</VirtualHost>
The apache variable HTTP_HOST
doesn't seem to be recognized in redirect directives.
So, is there any other way to use mod_alias to achieve the above effect?