Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I set up a website at, but recently bought the domain

Now I updated the information on Google via Webmaster Tools and it recommended we set up a 301 redirect from the .net to the .com. I have found how to do this by adding code like this to the .htaccess:

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*)$1 [R=301,L]

My problem is, both domains point to the same server, so am I correct in assuming this would try to redirect even if I visited the .com initially? If so, what is the correct way to accomplish this?

It may not matter, but I didn't want to cause any problems with my search rankings.

Thanks in advance!

share|improve this question
up vote 2 down vote accepted

For this use case I'd add a rewrite condition (RewriteCond) to be explicit about which domain you want to impose the rule against. E.g.:

Options +FollowSymLinks
RewriteEngine on  
RewriteCond %{HTTP_HOST} ^ [NC]  
RewriteRule (.*)$1 [R=301,L]

This way if the condition isn't met, your redirect won't fire. Also note that these can be chained, so you can assign multiple conditions.

See for more info. Very handy stuff lurking in that page.

share|improve this answer
Thanks, that worked fine :) It doesn't work for subdirectories however, for example does not redirect to - do you know how I could accomplish this? – user491704 Dec 19 '11 at 16:20
I think if you remove the $ symbol from the third line it will work for sub-directories. – Andrew Lambert Dec 19 '11 at 17:53
Thanks to you both - I've edited the original post. The "$" does anchor the condition to a 'bare' hostname (specifically, the end of line), so removing it should work for you. – mcauth Dec 19 '11 at 18:28

Your Answer


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.