Skip to content Skip to sidebar Skip to footer

Redirect Main Website To Sub Domain Based On Visitor IP Address (country)

I need help redirecting my website to sub domain based on visitor ip address (location). I have 3 specific websites I want to redirect visitors from Europe to eu.mysite.com I want

Solution 1:

You just use an API to resolve the visitor continent by IP and redirect to the corresponding URL :

$.getJSON("http://api.db-ip.com/v2/free/self").then(function(addrInfo) {
    if (addrInfo.continentCode == "EU") {
        document.location = "http://eu.example.com";
    } else if (...) {
        // handle other cases
    } else {
        document.location = "http://example.com";
    }
});

Post a Comment for "Redirect Main Website To Sub Domain Based On Visitor IP Address (country)"