Эти три правила должны делать все, что вы хотите:
RewriteEngine On
# Rewrite www.subdomain.example.com to subdomain.example.com
RewriteCond %{HTTP_HOST} ^www\.(.*)\.example\.com
RewriteRule (.*) http://%1.example.com/$1 [L,R=301]
# Rewrite example.com to www.example.com
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule (.*) http://www.example.com/$1 [L,R=301]
# Add trailing slash to all URIs without one
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [L,R=301]