How can a multilingual website visit websites in different languages according to the user's ip?

question:

our company"s website xxx.com
will be divided into Chinese version and overseas version
enter different domain names by default according to different ip
xxx.com/cn: China ip (Chinese mainland, Hong Kong, Macao and Taiwan)
xxx.com/en: non-Chinese ip

then the bottom of the website also provides users with switching regions and languages. After switching, the page is refreshed and the home page is visited

.

how can I do this requirement?
what does php need to do? What does the front end need to do? What does nginx need to do?

A novice has asked for advice.

Jun.16,2022

all php, all into the domain name xxx.com, and then

  1. get access to ip
  2. determine whether it is an overseas api or buy an ip library through a third party
  3. based on the judgment, use header () in the code, that is, redirect
  4. with 301 or 302.
When visiting a website visited by

, send a request to the backend first. After receiving the request, php can get the ip, go to the third repository according to ip to determine whether it is domestic, and then return a result. The frontend gets the result and jumps to different domain names. (when you visit element's official website, it will automatically determine whether it is a mainland user.)


php gets the user's ip, determines the domain name currently visited, and then determines whether it needs to jump to the domain name of the corresponding language.


IP is not easy to judge. You can get the language the user uses from the browser UA.


Domain name resolution on Aliyun supports the selection of resolution lines and access to regions that are not accessible. How to configure url such as xxx.com/en and xxx.com/cn in a domestic ip and a foreign ip


nginx?


you can try the Nginx GeoIP module

configure as follows

http {
    geoip_country         GeoIP.dat;
    geoip_city            GeoLiteCity.dat;
    geoip_proxy           192.168.100.0/24;
    geoip_proxy           2001:0db8::/32;
    geoip_proxy_recursive on;

country and city variables can be obtained directly after configuration

$geoip_country_code
: "CN" , "US" .

$geoip_city
: "Moscow" , "Washington" .


$geoip_latitude
.
$geoip_longitude
.

this information can be passed directly to the back-end php program

official website
http://nginx.org/en/docs/http...

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bee3c7-31bd6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bee3c7-31bd6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?