Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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   ^(.*)$ http://www.domain.com/$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

1 Answer 1

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

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

Your Answer

 
discard

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.