0

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]
Ben Pilbrow
  • 11,995
  • 5
  • 35
  • 57
Sam
  • 403
  • 3
  • 7
  • 23

1 Answers1

3
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 ...
Andy
  • 3,705
  • 1
  • 19
  • 9
  • 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