WordPress and Multiple Domains On One Site
If you have multiple domains pointing at your site it is important that the site has a preferential domain so that Google does not mistakenly regard the different domains as different sites.
Most of this can be achieved within the WordPress CMS by simply setting the preferred domain but we may still need to action a generic redirect outside of WordPress itself to ensure all domain variations are correctly redirected to the preferred domain.
Root 301 Domain Redirections in WordPress .htaccess
To redirect WordPress to one version of a domain we have to add some additional code to the .htaccess as below.
Default .htaccess
The default file is going to look something like this:
# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
WordPress .htaccess with Domain Wide 301 Rewrite
Lets assume we have two domains pointing at our site:
www.domain-A.com
www.domain-B.com
Our site is set up in the WordPress backend as www.domain-A.com so whilst any inner pages will link to this address pages can still be linked to and still render on the www.domain-B.com and domain-B.com variations of the second URL.
To remedy this we add two new rules to our htaccess file.
- Rewrite domain-B.com to www.domain-A.com
- Rewrite www.domain-B.com to www.domain-A.com
# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /
# New code to redirect from domain-A.com to www.domain-B.com & include the query string
RewriteCond %{HTTP_HOST} ^domain-A\.com
RewriteRule (.*) http://www.domain-B.com/$1 [R=permanent,QSA,L]
# New code to redirect from www.domain-A.com to www.domain-B.co.uk & include the query string
RewriteCond %{HTTP_HOST} ^www\.domain-A\.com
RewriteRule (.*) http://www.domain-B.com/$1 [R=permanent,QSA,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Putting it into Practice
Putting this into practice is pretty simple and you can take the example above and replace the domain-A and domain-B values and insert your own domains. This obviously only covers a site with two URLs but you can just as easily add another set of these rules with domain-C pointing to domain-A for as many URLs as are required.
Well folks, I hope that helps and if you need any help with WordPress or SEO for your WordPress site give me a shout. Oh, and please share this with the social buttons below if it helped you out!


Comments (2)
James Brown
| #
Thank you for this article.
Please can you clarify the sentence ‘Lets assume we have two domains pointing at our site’, specifically could this solution work for http://www.domain.co.uk and http://www.domain.com instead of http://www.domain-A.com
and http://www.domain-B.com ?
Reply
Marcus Miller
| #
Yep, totally, you still need to set one primary domain and WP will not rewrite by default at the site root if the hosting is set up to accept requests on both domains. Always check after making changes with web bug or some other header checker so you can make sure you are getting a 200 on your primary and a 301 on your alternative. Shout if that’s not clear.
Reply