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 want to make general rule for all my domains, so I don't have to specify each of them individually.

I have these two lines in my Apache config file:

RewriteCond   %{HTTP_HOST} ^domain\.com
RewriteRule   ^(.*)$$1 [R=301,QSA]

Now I have more domains pointing to the same directory. And I would have to repeat these 2 lines for each domain. I was trying to edit this condition and rule, but with no success to make them general to any domain without actually specifying domain name. Is it possible ?

share|improve this question

To redirect everything except (since that would be a loop) to, you'd want something like this:

RewriteCond   %{HTTP_HOST} !^www\.domain\.com$
RewriteRule   ^(.*)$$1 [R=301,QSA]
share|improve this answer

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.