I have a vhost that accepts all domains and subdomains from 4 top domain names, e.g. example.com
, example.org
, three.example.co.uk
etc.
I want the entire VHost to redirect to the exact same URL as requested, but HTTPS.
I know of this:
<VirtualHost *:80>
ServerName example.com
ServerAlias *.all *.other *.domains
Redirect permanent / https://example.com/
</VirtualHost>
but that won't work for subdomains, because explicit target URL.
It's so easy in nginx:
return 301 https://$host$request_uri;
so I thought Apache would have a thing for that, and it sort-of does, but this doesn't work (no Apache error, just broken redirect):
Redirect permanent / https://%{HTTP_HOST}/
Is there any way to use a domain/host variable? Bonus points for not using RewriteRule
!
Answer in Apache SSL New Domain Redirect is good enough. (Didn't see that one while typing question.)
Solution:
Using
%{HTTP_HOST}
in target URL seems to work fine with Apache 2.4.Any method without rewriting, like nginx does? Or not worth it?