Y
Y
yerdnaandrey2020-05-07 14:19:48
PHP
yerdnaandrey, 2020-05-07 14:19:48

How to redirect the user to the site depending on his country?

Hello. I have two folders:en and ru . I need to redirect the user to an index file in one of these folders depending on their location. Tell me how to implement all this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Nikolaev, 2020-05-07
@yerdnaandrey

If necessary, depending on the country, you can use, for example, geoIP (or any other service), which by IP will tell you the most likely country.
In general, there are many solutions to the initial situation:
1) Use GeoIP to determine the source of the request
2) Check the Accept-Language header and redirect depending on the language (option from Alexander )
3) Redirect to /ru/ (or /en/) depending on whether who is the primary one and there already do a pop-up hint with a city change (like "Our site is in other languages")

I
Ilya, 2020-05-07
@rpsv

When entering the root of the site, determine the country / language through services, such as: https://ip-api.com/docs/api:json
And then redirect to the desired section

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question