Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

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).

share|improve this answer
    
WP MU Domain Mapping 0.5.4.3 does this, just add two domains for a subsite and set the www one to have priority, and it redirects perfectly. The trailing slash should be googlable, and you have an example in the pasted .htaccess. –  Henrik Erlandsson May 30 at 7:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.