How do I redirect a user based on their location and IP address?

Austin Beresford
Published: 26 November 2020
Share:

The 20i CDN nodes have inbuilt support for GeoIP. 

This means that each request gets an X-Country HTTP Header set which can be used to redirect traffic from specific countries. 

For example, if you wanted to redirect UK traffic that hits the '.com' version of your site you could add this in a .htaccess file. 

RewriteCond %{HTTP:X-Country} UK [nc]

RewriteRule (.*) http://my-new-domain.co.uk/$1 [L,R=302]

The free 20i CDN is available on our shared Web Hosting, WordPress Hosting, Reseller Hosting and Managed Hosting.