htaccess redirect all subdomains + www to domain with cname, vhosts and htaccess

redirect *.domain.com -> domain.com

Just change your rule to this:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^[^.]+\.(domain\.com)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L,NE]

Set your server alias to *.domain.com in your Apache config, below your server name:

ServerName domain.com
ServerAlias *.domain.com

Everything to non-www:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+)\.domain\.com$   [NC]
RewriteRule ^ http://domain.com/  [L,R]

Everything to www:

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^(.+)\.domain\.com$   [NC] 
RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule ^ http://www.domain.com/  [L,R]