Forum Moderators: phranque
i'm absolutely new to mod_rewrite and I need some help to start using it.
I have 2 domains pointing to the same directory:
domain.com
domain.it
The first one is in english (.com) and the other one in italian (.it). The site is bilingual (italian and english) and according to the language chosen it should redirect to the corresponding domain eg:
www.domain.com => english
www.domain.it => italian
The site uses a get variable "lang" to load the corresponding language so I should deny the combination domain.com?lang=it and domain.it?lang=com.
I know that for most of you it should be really simple but I am abolutely new to apache mod_rewrite and the guides I've found around the web aren't helpful.
Thank you for your help
If so, that could be done with something like this:
# If no lang variable in URL, map .it tld to "lang=it" or .com to "lang=en"
RewriteCond %{QUERY_STRING} !(&?lang=[^&]+&?)
RewriteCond %{HTTP_HOST}<>it ^(www\.)?example\.it<>(.+)$ [OR]
RewriteCond %{HTTP_HOST}<>en ^(www\.)?example\.com<>(.+)
RewriteRule (.*) /$1?lang=%2 [QSA,L]
#
# Fix invalid domain-lang combination URLs (remove bad lang name/value so that domain takes precedence)
RewriteCond %{HTTP_HOST} (www\.)?example\.com
RewriteCond %{QUERY_STRING} ^(([^&]+&)*)lang=it(&.*)?
RewriteRule (.*) http://www.example.com/$1?%1&%3 [R=301,L]
#
# Fix invalid domain-lang combination URLs (remove bad lang name/value so that domain takes precedence)
RewriteCond %{HTTP_HOST} ^(www\.)?example\.it
RewriteCond %{QUERY_STRING} ^(([^&]+&)*)lang=en(&.*)?
RewriteRule (.*) http://www.example.it/$1?%1&%3 [R=301,L]