Dealing with Multiple Domain Names Properly

Though it’s less popular these days, some people desire to have multiple domain names pointing to the same site. For example, say you have three domain names:

The problem is that, especially if you market all three domains, people are free to link to any of these domains. That’s a major duplicate content issue. You must pick a “standard” domain and permanently redirect the other domains to that domain.

Let’s pick This is how to do it with mod_rewrite:

RewriteEngine on
RewriteCond % {HTTP_HOST} !^www\.example\.com
RewriteRule ^(.*)$$1 [R=301,L]

Done! Now everything will get redirected to Let’s analyze the rule in detail.

This is the first time you’re using RewriteCond to place a condition for the rule that follows. In this case, you’re interested in verifying that the site has been accessed through Take another look at the RewriteCond line:

RewriteCond % {HTTP_HOST} !^www\.example\.com

This line specifies a condition that is true when the host name (HTTP_HOST) is not(!) The rewrite rule captures the entire query string of the original URL, as (.*), and passes it to, doing a 301 redirect to the new location. This way, for example, a query to http://www.example/org?query=string would be 301 redirected to

Your Ad Here

JavaScript, ASP.Net & PHP Web Developer. Connect with me on Facebook and Twitter.

Share This Post

Recent Articles

Powered by Paras Babbar · Designed by Paras Babbar