I want to do this:
if (user from other website, like google, or input our website URL directly in the browser)
{
//redirect according to browser languge
if (!preg_match('/en-US/', $_SERVER['HTTP_USER_AGENT']))
{
wp_redirect("http://cn.gearor.com");
}
}
I don’t know how to write the first if statement, I don’t know how to get the from URL and how to check it’s my website or other websites. If it’s my website, do nothing, if it’s not my website, check if the browser is English, if not, redirect to http://cn.gearor.com
You want something like:
I changed your language check to use HTTP_ACCEPT_LANGUAGE, and to also not be case sensitive (Opera uses en-US where Firefox and IE use en-us in my tests).
You could also consider using
/^en-us/iif you are checking for the DEFAULT language. The language strings can contain multiple languages, comma delimited.