How to Force WWW. in Domain With WordPress MU Domain Mapping Plugin?

I created a thread (How to make www. and no www. Go to same site, for all sites?) in the support forums for the WordPress plugin: WordPress MU Domain Mapping.

Everything is fine and dandy. I have a base domain, along with several other domains. I have added all of the domains successfully.

However, I get www.domain.com and domain.com to work, but they’re separate URL structures. I need domain.com to redirect to www.domain.com, for each of the mapped domains, much like my base domain does.

How can I achieve non-www domains to redirect to www domains for each of my mapped domains?

Solutions Collecting From Web of "How to Force WWW. in Domain With WordPress MU Domain Mapping Plugin?"

Answered from this thread.

Summary:

The .htaccess redirect for www/non-www…

# www redirect
RewriteCond %{HTTP_HOST} ^subdomain.com
RewriteRule ^(.*)$ http://www.subdomain.com/$1 [R=301,L]

Put it ABOVE your WordPress rules on domain.com. Should work.

Example:

RewriteEngine On

# DOMAIN #1 - Redirect non-www urls to www
RewriteCond %{HTTP_HOST} ^domain1.com
RewriteRule ^(.*)$ http://www.domain1.com/$1 [R=301,L]

# DOMAIN #2 - Redirect non-www urls to www
RewriteCond %{HTTP_HOST} ^domain2.com
RewriteRule ^(.*)$ http://www.domain2.com/$1 [R=301,L]

# DOMAIN #3 ... ETC - Redirect non-www urls to www
RewriteCond %{HTTP_HOST} ^domain3.com
RewriteRule ^(.*)$ http://www.domain3.com/$1 [R=301,L]

RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

It would be nice if someone could explain how to force a trailing slash to each of my domains as well (if not present).