I\'m attempting to redirect www to non-www for both HTTP and HTTPS requests. My root .htaccess looks like this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^w
The first rule is taking precedence over https request because it simply met the rewrite condition. The first rule basically tells that match the domain and you can have your rewriterule to kick off. Instead add another condition which tells if its not https request
So try this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteCond %{SERVER_PORT} !^443
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteCond %{SERVER_PORT} ^443
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
You need ssl certificate for https protocol to work
Also I've added [L] flag which tells to not process further rules