Compact Redirects in Apache/htaccess. How? [An Elegant Coding Question]
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]
Solution 1:
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 ...