How to block traffic from specific countries using CloudFlare

If for any reason you want to block visitors from any country, the solution is extremely simple!

First, enable the IP Geolocation in CloudFlare

IP Geolocation card in Network app, Cloudflare dashboard.

And then everything can be done from .htaccess file, via apache server:

# Block countries - IP Geolocation
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP:CF-IPCountry} ^(CN|IR|PK|TH|BD)$
RewriteRule ^ - [F,L]

The country code list can be find from the below link:

Leave a Reply

Your email address will not be published. Required fields are marked *