I'm trying to redirect my site from http to https and from www to non-www at the same time. This code from Andron here works but with a few glitches. I've slightly tweaked it and redirected everything from the non-https to https as well.
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
For the following situations the redirect works flawlessly and redirects to the non-www https
version:
domain.com
www.domain.com
www.domain.com/page
However, when I enter the domain.com/page
or http://domain.com/page
I see only the non-secure http non-www
version.
How do I make sure that all URLs redirect to the secure https non-www
version of the site?