how to redirect www subdomain to non-www when domain is redirected to www
Keep this one rule for all the sub-domains:
# rule for forcing www on main domainRewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]# rule for removing www on sub domainsRewriteCond %{HTTP_HOST} ^www\.([^.]+\.mydomain\.com)$ [NC]RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]