WordPress and Multiple Domains On One Site

Written by Marcus Miller on . Posted in SEO, WordPress

WordPress Logo - 301 rewriting multiple domains in WordPressIf 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.

  1. Rewrite domain-B.com to www.domain-A.com
  2. Rewrite www.domain-B.com to www.domain-A.com
To do this we add two new sets of rules within the # BEGIN WordPress & # END WordPress tags.
# 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! :)

Be Sociable, Share!

    Marcus Miller

    Marcus has been creating and marketing websites since, well, lets just say before the Millennium and is currently focused on Internet Marketing and SEO. If you have a problem, and no one else can help, and if you can find the contact page, Marcus can help. Email | Twitter | Google+

    Comments (2)

      • 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

    Leave a comment