# Redirect visitors from a specific country

Sometimes you want to redirect visitors from a specific country to a special landing page, sometimes you have multiple shops on different domains for each country and you want to redirect visitors to the correct domain or maybe something completely different.

We've made it very easy with the "ip_country" method available on the request object, which returns the visitors country code in the iso_3166_2 format. Returns "XX" if the country is unknown.

Client-side redirect

<script>
    if ('{{ request.ip_country }}' == 'DK') {
        window.location.replace("https://google.dk");
    }
</script>

Server-side redirect

<script>
    {% if request.ip_country == 'DK' %}
        {{ 'https://google.dk' | force_redirect }}
    {% endif %}
</script>

Under the hood we are using Cloudflare's IP geolocation implementation, so make sure it's turned on for your domain, which it is by default.

You can even do stuff like the following in your templates.

{% if request.ip_country == 'DK') %}
    <h1>Welcome Viking!</h1>
    <img src="/danish-banner.jpg">
{% else %}
    <h1>Welcome Stranger</h1>
    <img src="/world-banner.jpg">
{% endif %}