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
!
RewriteRule
?RewriteRule
?RewriteRule
as i have done this kind of setup many times. Also Googling gives a lot of samples, you've found one :) Glad it works for you now. have a nice day :)mod_rewrite
method. If this could be achieved using onlyredirect
i would be glad to learn about it also, just like you !! :) :)