Help needed with GEO redirecting script

JohnKowalski

Junior Member
Joined
Jan 11, 2016
Messages
196
Reaction score
208
Hello, this script below redirects US users to google.us(com) and the rest of the world to google.be

How to modify the script so it could redirect to different countries websites?


example:

traffic from Italy redirects to google.it
traffic from Spain redirects to google.es
traffic from France redirects to google.fr
traffic from Germany redirects to google.de

etc.



Przechwytywanie.png




I,ve tried to modify the code with help sources available on the internet, but nothing seems to work so far.


Sorry had to make a screen shot, there was a popup warning not allowing me to place it inside code tag.


Thanks in advance for any kind of help.
 
Try this:
Code:
if(geoplugin_countryCode()=='US'){
    location.href = "https://google.us";
}elseif(geoplugin_countryCode()=='IT'){
    location.href = "https://google.it";
}elseif(geoplugin_countryCode()=='ES'){
    location.href = "https://google.es";
}elseif(geoplugin_countryCode()=='FR'){
    location.href = "https://google.fr";
}elseif(geoplugin_countryCode()=='DE'){
    location.href = "https://google.de";
}else{
location.href = "https://google.com";
}

NB! I have not tested this, just type it in notepad quickly.

You will need to confirm the country codes are correct, I have just guessed.
The last location will be the default that will be redirected to if none of the other country codes match.



HTH
 
Thanks for giving a shot but unfortunately it doesn't work. No redirection to any country now. I thing I might have tried it too before :)
 
If the redirects work with your original code, and you confirmed that the country codes are valid, this really should work.
Not sure of your programming skills, so apologies if this is something that is obvious to you, but did you replace all the code within the script tags with the code I pasted?
 
Try this:
Code:
if(geoplugin_countryCode()=='US'){
    location.href = "https://google.us";
}elseif(geoplugin_countryCode()=='IT'){
    location.href = "https://google.it";
}elseif(geoplugin_countryCode()=='ES'){
    location.href = "https://google.es";
}elseif(geoplugin_countryCode()=='FR'){
    location.href = "https://google.fr";
}elseif(geoplugin_countryCode()=='DE'){
    location.href = "https://google.de";
}else{
location.href = "https://google.com";
}

NB! I have not tested this, just type it in notepad quickly.

You will need to confirm the country codes are correct, I have just guessed.
The last location will be the default that will be redirected to if none of the other country codes match.



HTH

This should 100% work.
 
Sorry guys the screenshot again, but cloudfare doesn't allow me to post with code tags.

My programming skils are very low, and this is how the code looks like now with the help of @darnoldi and it doesn't work.

Przechwytywanie.png
 
Sorry guys the screenshot again, but cloudfare doesn't allow me to post with code tags.

My programming skils are very low, and this is how the code looks like now with the help of @darnoldi and it doesn't work.

Przechwytywanie.png
Are there any error codes in console. Maybe the plugin hasnt got them defined and cause the script to fail?
 
It might be because of `Mixed Content` so your website might have SSL (https://) and the plugin url only has (http://)
 
Last edited by a moderator:
It might be because of `Mixed Content` so your website might have SSL (https://) and the plugin url only has (http://)

I couldn't edit on the post so i'll reply here.


HTML:
$.get("https://wtfismyip.com/json", function(response) {
        var cc = response.YourFuckingCountryCode;
if(cc === 'US'){
    location.href = "https://google.us";
}else if(cc === 'IT'){
    location.href = "https://google.it";
}else if(cc === 'ES'){
    location.href = "https://google.es";
}else if(cc === 'FR'){
    location.href = "https://google.fr";
}else if(cc === 'DE'){
    location.href = "https://google.de";
}else{
    location.href = "https://google.com";
}
   });

PS: DON'T FORGET TO ADD JQUERY
 
Try this:
Code:
if(geoplugin_countryCode()=='US'){
    location.href = "https://google.us";
}elseif(geoplugin_countryCode()=='IT'){
    location.href = "https://google.it";
}elseif(geoplugin_countryCode()=='ES'){
    location.href = "https://google.es";
}elseif(geoplugin_countryCode()=='FR'){
    location.href = "https://google.fr";
}elseif(geoplugin_countryCode()=='DE'){
    location.href = "https://google.de";
}else{
location.href = "https://google.com";
}

NB! I have not tested this, just type it in notepad quickly.

You will need to confirm the country codes are correct, I have just guessed.
The last location will be the default that will be redirected to if none of the other country codes match.



HTH

else if*
 
Ok so there was a bug in my code.

The following is tested and works 100%, but cannot talk to how cloudflare would affect it.

code.png
 
Out of interest is there any reason you're doing this client-side rather than server-side?

Also this:
"
If geoplugin.net was responding perfectly, then stopped, then you have gone over the free lookup limit of 120 requests per minute.

We automatically block all requests coming from an IP or a domain name if the number of requests exceeds 120 lookups per minute. This is explained in our Acceptable Use Policy. This block comes in the form of a HTTP/1.1 403 Forbidden reply from geoplugin.net

This block is automatically removed 1 hour after the last time your server stopped sending more than 120 requests a minute.
"
 
@Sebastiann thank you! The script you shared works pefectly. I'm doing this client-side because, I will use it for affiliate offers, this way it's easy for me to modify the code on the spot , at list for now.

Thanks very much to all of you guys for your help!

You're all Great !!!!!!!!!!!!

:)
 
For OP: This geo service is only reachable via http. You'll run into mixed content issues.

Yeah, I was going to say that was well haha - something like a local server side IP stack solution would be better.

You can see a demo of the way I'd normally do it that I wrote up as a concept here: https://github.com/prescience-data/shopify-cloak

These are the important parts:

WtATjn.jpg


iSbX3r.jpg
 
Back
Top