I need to redirect www and non www to https. I have looked everywhere on stackoverflow but can\'t find quite what I\'m looking for.
The rules are:
This is the only way it works for me - with !on
instead of off
and with %{ENV:HTTPS}
instead of %{HTTPS}
:
#non-www. http to www. https
RewriteCond %{ENV:HTTPS} !on
RewriteCond %{HTTP_HOST} ^(www\.)?yourdomain\.com$
RewriteRule (.*) https://www.yourdomain.com/$1 [R=301,L]
#non-www. https to www. https
RewriteCond %{ENV:HTTPS} on
RewriteCond %{HTTP_HOST} ^yourdomain\.com$
RewriteRule (.*) https://www.yourdomain.com/$1 [R=301,L]