I was using this code to remove www from my domain:
# remove www
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
My problem is that I usually use subdomains and it doesn’t work for them. (www.sub.example.com).
How do I rewrite to remove www whatever the domain is and even if it has subdomains?
Try this:
This is a bit more correct than the other solution.
Edit:
I removed [L] as it isn’t applicable here.
Though in most cases [NC] non-case sensitive is recommended.