Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


GEO redirection
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

GEO redirection

armandorgarmandorg Member, Host Rep

So what i have 'failed' to do so far is to redirect visitors based on their country to a spefic folder. I have multiple websites for my clients which uses more than 4-5 languages and all of them have a speciic folder such as /fr/ or /de/. Anyways, what i'm trying to do is redirect only the countries which have a folder, for example france and germany, all the other countries which do not have a language are remained at the root page, which normally would be english version.

I tried to implement this with some geo php script, however the english version[root] is not in some folder such as /en/ and when i added the script in the index.php, when a visitor was from england lets say, the redirect just kept on going and made the site unavailable[too many redirects].

Looking forward to some solutions, thanks!

Comments

  • Do if the geo IP is English & other countries that speaks English Todo nothing then else carry on with that argument.

  • armandorgarmandorg Member, Host Rep
    edited September 2018

    @Jake4 said:
    Do if the geo IP is English & other countries that speaks English Todo nothing then else carry on with that argument.

    Fixed it!

    With this plugin: https://www.geoplugin.com/

    And this code:

    <?php require_once('geoplugin.php'); $geoplugin = new geoPlugin(); $geoplugin->locate(); $var_country_code = $geoplugin->countryCode; // redirect based on country code: if ($var_country_code == "DE") { header('Location: /de); } ?>

    Works like a charm : )

  • Stop and don't use geoip for this.

    You should be respecting https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language

    Thanked by 1CyberMonday
  • armandorgarmandorg Member, Host Rep

    @hzr said:
    Stop and don't use geoip for this.

    You should be respecting https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language

    If i don't? : )

  • armandorg said: If i don't? : )

    Bad UX :)

    The reasoning behind this is that people typically want a specific language or are most comfortable with a specific language..

    if I am in germany but don't speak german and have my OS set to english, then accept-language will request en-GB;en but geoip would try to do de.

    If I only speak french but I'm on holiday in spain, my browser will almost certainly send fr-FR;fr in this header - which is what I want, but geoip would try to send es.

  • Yeah @hzr is right. Use geoip to redirect to the closest server if you want (dns level) but focus on Accept-Language for that kind of redirection. Don't forget to also add text links to each version for search engine bots & users with javascript disabled!

  • armandorgarmandorg Member, Host Rep

    @datanoise said:
    Yeah @hzr is right. Use geoip to redirect to the closest server if you want (dns level) but focus on Accept-Language for that kind of redirection. Don't forget to also add text links to each version for search engine bots & users with javascript disabled!

    Acually the idea is like this, we redirect users depending on their location to a specific folder in their native language. In the top menu there is a language switcher which they can use to get back to a language they desire. The redirect works only for the root website.

  • @armandorg said:

    @datanoise said:
    Yeah @hzr is right. Use geoip to redirect to the closest server if you want (dns level) but focus on Accept-Language for that kind of redirection. Don't forget to also add text links to each version for search engine bots & users with javascript disabled!


    Acually the idea is like this, we redirect users depending on their location to a specific folder in their native language. In the top menu there is a language switcher which they can use to get back to a language they desire. The redirect works only for the root website.

    Dutch is my native language but I have set my system language to english and would like to get the english version of sites because of this setting. If I were you I would reconsider your solution because after all Accept-language is meant for these sort of things and like you said, users can still switch to another language of their choice.

    Thanked by 1datanoise
Sign In or Register to comment.