Mark Dorison

Optimizing Multiple Domains for Google Using Apache's mod_rewrite

If you own more than one domain but point them all to the same site, a portion of your virtual host file may look something like this:

<VirtualHost *:80>
   ServerName maindomain.com
   ServerAlias www.maindomain.com alternatedomain.com
</VirtualHost>

The problem here is that Google sees the same content being served on multiple domains and will knock down your search ranking as a result. The way to remedy the situation is to utilize Apache's mod_rewrite so that a 301 request pushes the user to your main url. The only caveat being that no matter which domain you type into the browser url bar, it will then be rewritten to the main domain. Here is an example of the code below that you can add to your virtual host file:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.maindomain.com|alternatedomain.com) [NC]
RewriteRule ^(.*)$ http://maindomain.com$1 [R=301,L]

Save the file, restart Apache, and your alternate domains should then be rewritten to your main domain, your Google ranking preserved, and all is right with the world.

← Home