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.

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} ^website.de$    // works fine
RewriteRule ^$ de/home [R=301,L]

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

RewriteCond %{HTTP_HOST} ^website.com$    // doesnt work well
RewriteCond %{HTTP_HOST} ^website.org$    // doesnt work well
RewriteCond %{HTTP_HOST} ^website.net$    // doesnt work well
RewriteRule ^$ en/home [R=301,L]
share|improve this question

1 Answer 1

up vote 2 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
1  
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
1  
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

 
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.