There's a few similar questions which I tried to work out the answer from, but so far I have been unsuccessful. Please advise how I can always redirect http to https (and also remove www. from the hostname in the process). Also a side note, it would be nice to do this inside the main Apache conf rather than .htaccess
- but I imagine this will not apply to most people.
- .htaccess redirect www to non-www with SSL/HTTPS
- Redirect subdomain request to subdirectory + https (using .htaccess)
- htaccess redirect for non-www both http and https
Update:
I've added this snippet to a VirtualHost
section:
RewriteCond %{HTTP_HOST} ^www\.(.*)
RewriteRule ^.*$ https://%1/$1 [R=301,L]
... but it has no effect when I access http://www.domain
(it should redirect to https://domain
)
Update 2:
It had no effect because I did not use RewriteEngine on
- so it works now:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)
RewriteRule ^.*$ https://%1/$1 [R=301,L]