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]
</IfModule>

The country code list can be find from the below link:
http://www.ip2country.net/ip2country/country_code.html