我有以下规则可以将中国用户重定向到网站的中文版本:
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]
这很好用。
但是,应该有一个链接可以将他们带回到网站的英文版本,这只是普通域(www.example.com)。
但这只是将他们直接重定向回中文网站,因为它符合规则。所以我需要这样做,所以只有当引用者不是 ch.example.com 时才会触发上述规则。
我试过这样的事情:
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]
但它不起作用。