views:

18

answers:

1

Hi, I am trying to perform the following rule in htaccess:

 www.domain.com/folder/?id=14077&c=en-gb    ->  www.domain.com/folder/?id=14077 
 www.domain.com/folder/?c=en-gb&ID=14077    ->  www.domain.com/folder/?id=14077 
 www.domain.com/folder/?id=14077&c=fr-fr    ->  www.domain.fr/folder/?id=14077 
 www.domain.com/folder2/?c=fr-fr&ID=14077   ->  www.domain.fr/folder2/?id=14077
 www.domain.com/folder2/?c=en-us&ID=14077   ->  www.domain.us/folder2/?id=14077 

Basically take out the "c" part of the querystring and redirect it to a new domain, based on the following rules:

 c=en-gb -> www.domain.com
 c=fr-fr -> www.domain.fr
 c=en-us -> www.domain.us

Any help welcome!

+1  A: 

Admittedly, I'm not sure if this is a task best solved by mod_rewrite...but what the hell, why not:

(Not fully tested, but it seems to work well)

RewriteEngine On
RewriteCond %{QUERY_STRING} (.*)(\A|&)c=([A-Za-z\-]+)&?(&.*)?$
RewriteRule .* - [E=SWITCHLANG:%3,E=QSONE:%1,E=QSTWO:%4]

RewriteCond %{ENV:SWITCHLANG} =en-gb [NC]
RewriteCond %{HTTP_HOST} !(.*)\.com$
RewriteRule (.*) http://www.domain.com/$1?%{ENV:QSONE}&%{ENV:QSTWO}

RewriteCond %{ENV:SWITCHLANG} =fr-fr [NC]
RewriteCond %{HTTP_HOST} !(.*)\.fr$
RewriteRule (.*) http://www.domain.fr/$1?%{ENV:QSONE}&%{ENV:QSTWO}

RewriteCond %{ENV:SWITCHLANG} =en-us [NC]
RewriteCond %{HTTP_HOST} !(.*)\.us$
RewriteRule (.*) http://www.domain.us/$1?%{ENV:QSONE}&%{ENV:QSTWO}
Tim Stone
Fantastic, I had given up hope of achieving this!
bateman_ap