
I started a new blog Gearor.com, which is a gadgets and tech blog. I also set up a Chinese version using sub domain cn.Gearor.com. So I tried to do one thing, if visitors come with a Chinese browser, the website will automatically redirect them to the Chinese page.
At the first time, I simply check the browser language, if it’s Chinese, the page will redirect to Chinese page. There is one problem with this method. I made a English link in Chinese page so that Chinese users can visit English page if they want, but after I added the redirection, Chinese users can’t visit English page, every time they click the link, they will be redirect to Chinese page.
This means I also need to check the referral URL, if it’s from my own website, geaor.com or cn.gearor.com, we don’t need to do the redirection. Jasonbar from StackOverFlow helps me to fix this. By the way, StackOverFlow is a really great website, there are a lot of great programmers there, and they are all willing to help you. Here is my final code which is working fine on my website:
if (!preg_match('%gearor.com%i', $_SERVER['HTTP_REFERER']))
{
if (!preg_match('%cn.gearor.com%i', $_SERVER['HTTP_REFERER']))
{
if (preg_match('/zh-cn/i', $_SERVER['HTTP_ACCEPT_LANGUAGE']))
wp_redirect('http://cn.gearor.com');
}
}
If you are developing multi languages website, this may help you too.
Feel free to visit our Forum, subscribe our RRS Feed for news updates, and follow us on Twitter.
Pingback: Zack Live
Pingback: Zack Live