Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

when setting my redirects in htaccess, i have trouble setting/combining various domains when they all go to the same homepage. I can do them separate, but that isn't neat/elegant. How to rewrite the third paragraph sothat it works?

RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{HTTP_HOST} ^$    // works fine
RewriteRule ^$ de/home [R=301,L]

RewriteCond %{HTTP_HOST} ^$    // works fine
RewriteRule ^$ fr/home [R=301,L]

RewriteCond %{HTTP_HOST} ^$    // doesnt work well
RewriteCond %{HTTP_HOST} ^$    // doesnt work well
RewriteCond %{HTTP_HOST} ^$    // doesnt work well
RewriteRule ^$ en/home [R=301,L]
share|improve this question
up vote 3 down vote accepted
RewriteCond %{HTTP_HOST} ^website\.(com|org|net)$
RewriteRule ^$ en/home [R=301,L]

Also a better way of writing all of them:

RewriteCond %{HTTP_HOST} ^website\.(fr|de)$
RewriteRule ^$ %1/home [R=301,L]

RewriteCond %{HTTP_HOST} ^website\.(com|org|net)$
RewriteRule ^$ en/home [R=301,L]

Just for another note, you can combine multiple RewriteCond's as 'or' conditions using [OR], e.g.:

RewriteCond ... [OR]
RewriteCond ...
RewriteRule ...
share|improve this answer
Increadibly creative fashion of rewritig them! It think that is it, Andy, this will instantly erase 20 lines of code from my htacces. Thanks! – Sam Dec 19 '10 at 17:53
Where does the RewriteCond %{REQUEST_URI} ^/$ go? Just one time at the top or not needed? – Sam Dec 19 '10 at 17:56
It's not needed as the RewriteRule's ^$ does the job. However, if it was needed, it would need to be in each set of rules. – Andy Dec 19 '10 at 17:58
So, when combining, all RewriteCond end with a [OR] except the last RewriteCond (the one before the RewriteRule), right? – Sam Dec 19 '10 at 18:19
Yes, the [OR] makes it so the next RewriteCond is or'd with the preciding statement, e.g. multiple ones will be like a or b or c. It's not needed for the last condition. – Andy Dec 19 '10 at 18:32

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.