WebSite X5Help Center

 
Craig K.
Craig K.
User

Automatic redirect based on location  en

Author: Craig K.
Visited 1639, Followers 1, Shared 0  

How do you direct visitors automatically to the right page based on their geographic location (I'm interested in country)?

Posted on the
11 ANSWERS - 6 USEFUL
Paul M.
Paul M.
Moderator

Hello Craig,

Have a look at this article in the official WebSite X5 Guide:

How to set up an automatic redirection according to the detected Browser language

Redirection based on the language employed by the browser is the closest you will get to a built-in solution for geographic location.

Otherwise you would have to employ custom programming based on IP address, and this has its own set of drawbacks.

Kind regards,

Paul

Search the WebSite X5 Help Center

Read more
Posted on the from Paul M.
Craig K.
Craig K.
User
Author
Paul M.
Hello Craig, Have a look at this article in the official WebSite X5 Guide: How to set up an automatic redirection according to the detected Browser language Redirection based on the language employed by the browser is the closest you will get to a built-in solution for geographic location. Otherwise you would have to employ custom programming based on IP address, and this has its own set of drawbacks. Kind regards, Paul Search the WebSite X5 Help Center

Okay thanks, unfortunately language won't be able to distinguish between the countries I'm interested in as they all speak English.

Read more
Posted on the from Craig K.
Craig K.
Craig K.
User
Author

Here is another using Javascript, which is client side, so possibly easier to implement. One problem with this (and your suggestion) they both rely on APIs which is probably slower than solutions that install a database on the server (such as IP2location). 

https://gist.github.com/ipapi-co/b28ac4efaf8aa3e8596d202f7edc3586

Read more
Posted on the from Craig K.
 ‪ KolAsim ‪ ‪
 ‪ KolAsim ‪ ‪
Moderator
Best User of the month ESBest User of the month PT
Craig K.
... ... ...  ... ...  unfortunately language won't be able to distinguish between the countries I'm interested in as they all speak English.

(It > En) ... if you know the browser acronyms of the EN country languages you are interested in, for example [en-us] | [en-au], then you can condition this is my exclusive code, CLIENT (browser) side, (no API)!
... as it is now, it works with my browsers in IT, Chrome, Firefox, Internet Explorer ...
the languages IT, FR, EN, must be in the sub-directories it/, fr/, en/

... my original code, x INDEX - HEAD:

<script>
window.onload=function(){
var linguaK = navigator.languages && navigator.languages[0] || navigator.language || navigator.userLanguage;
linguaK = linguaK.toLowerCase();
if (linguaK.indexOf("it") != -1) {
location.href = "it/index.html";}
else if (linguaK.indexOf("fr") != -1) {
location.href = "fr/index.html";}
else if (linguaK.indexOf("en") != -1) {
location.href = "en/index.html";}
}
</script>

.

ciao

.

Read more
Posted on the from  ‪ KolAsim ‪ ‪
Craig K.
Craig K.
User
Author
 ‪ KolAsim ‪ ‪
Craig K.... ... ...  ... ...  unfortunately language won't be able to distinguish between the countries I'm interested in as they all speak English. (It > En) ... if you know the browser acronyms of the EN country languages you are interested in, for example [en-us] | [en-au], then you can condition this is my exclusive code, CLIENT (browser) side, (no API)! ... as it is now, it works with my browsers in IT, Chrome, Firefox, Internet Explorer ... the languages IT, FR, EN, must be in the sub-directories it/, fr/, en/ ... my original code, x INDEX - HEAD: <script> window.onload=function(){ var linguaK = navigator.languages && navigator.languages[0] || navigator.language || navigator.userLanguage; linguaK = linguaK.toLowerCase(); if (linguaK.indexOf("it") != -1) { alert("SI"); alert(linguaK); location.href = "it/index.html";} else if (linguaK.indexOf("fr") != -1) { location.href = "fr/index.html";} else if (linguaK.indexOf("en") != -1) { location.href = "en/index.html";} } </script> . ciao .

Thanks. I wonder if this would also be possible using Websitex5's built-in entry page feature with automatic language detection... or doesn't it go as far looking at regional variations of languages - like US vs UK vs SA english? Also, I looked at my browser and it is not set correctly, it is set automatically to US for some reason in Chrome.

Read more
Posted on the from Craig K.
 ‪ KolAsim ‪ ‪
 ‪ KolAsim ‪ ‪
Moderator
Best User of the month ESBest User of the month PT

... I currently cannot try, I am without PC and without program, but my code is simple and in theory it should be valid by conditioning correctly for the languages of interest, by modifying the code ...
... do this TEST and tell me the result you get with the various keyboards, US, UK, etc., maybe attach the various STAMP/screenshots...
... put this code in an HTML Code Object:
<script>
linguaK = navigator.languages && navigator.languages[0] || navigator.language || navigator.userLanguage;
alert(linguaK);
</script>

.

ciao

.

Read more
Posted on the from  ‪ KolAsim ‪ ‪
Axel  
Axel  
User

Hello KolAsim,

Here your detection is based on navigator values and user preference.

But you can use a navigator in english and be based  into japan or china or brasil . So the detection is not based in your case on the location of the user !

I missed something foot-in-mouth

Axel

Read more
Posted on the from Axel  
John S.
John S.
User

Hello Craig

Instead of the language you could find the country code by the IP.

You could try this :

var country_code = null; $.getJSON('http://ipinfo.io/' + userip, function(data){ country_code = data.country; alert(country_code); });

Some information here : https://stackoverflow.com/questions/673905/best-way-to-determine-users-locale-within-browser

And here : https://stackoverflow.com/questions/17680413/get-visitors-language-country-code-with-javascript-client-side

Read more
Posted on the from John S.
 ‪ KolAsim ‪ ‪
 ‪ KolAsim ‪ ‪
Moderator
Best User of the month ESBest User of the month PT
Axel  
Hello KolAsim, ...  ... ... ... ... ... ... ... ... ... ...  So the detection is not based in your case on the location of the user ! I missed something Axel
 ‪ KolAsim ‪ ‪
... ... ... if you know the browser acronyms of the EN country languages you are interested in, for example [en-us] | [en-au], then you can condition this is my exclusive code, CLIENT (browser) side, (no API)! ... ... ... ... 

... as I said before, simply in a simple JS browser; ... no PHP, no API, no .htaccess, ... no complications ...
...  ... on the net, as we have seen, there are many other solutions for all tastes, but not so immediate ...

... ciao... wink

.

Read more
Posted on the from  ‪ KolAsim ‪ ‪