I have the following rules working to redirect chinese users to the chinese language version of the site:
RewriteCond %{HTTP:Accept-Language} ^zh [NC]
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://ch.example.com/$1 [L,R=301]
RewriteCond %{HTTP:Accept-Language} ^zh [NC]
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://ch.example.com/$1 [L,R=301]
This works great.
However, there is a link that is supposed to take them back to the english language version of the site, which is just the normal domain (www.example.com).
But this just redirects them straight back to the chinese site, because it matches the rules. So I need to make it so the above rules are trigger ONLY if the referer is NOT ch.example.com.
I tried something like this:
RewriteCond %{HTTP:Accept-Language} ^zh [NC]
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http?://ch\.example\.com/ [nc]
RewriteRule ^(.*)$ http://ch.example.com/$1 [L,R=301]
But it doesn't work.
What about when the user views their second page on the English site, it will redirect to Chinese. A better method is to set a cookie and then check it:
For example: http://www.askapache.com/htaccess/htaccess-fresh.html#Set_Cookie_based_Requested_directory