You can enable IP Geolocation to have CloudFlare geolocate visitors to your website and pass the country code to you.
Redirect web traffic based on Country origin to subdomain or to different web site.

You will find the IP geolocation option by going to:
Webiste –>CloudFlare Settings –>IP Geolocation

Direct link is:

Once enabled, Cloudflare will then add a header called “CF-IPCountry” to all requests to your website.

Redirect web traffic based on Country origin

Here are a couple of examples of how to access/store this value:

$country_code = $ENV{"HTTP_CF_IPCOUNTRY"}; # to access in Perl
$country_code = $_SERVER["HTTP_CF_IPCOUNTRY"]; // to access in PHP

CloudFlare includes this information for both IPv4 and IPv6 addresses

In your website code capture that header and redirect traffic.
Redirect web traffic based on Country origin PHP sample:

$country_code = $_SERVER["HTTP_CF_IPCOUNTRY"];



ASP.NET example:

Subscribe To Our Newsletter

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!