home Tutorial Blocking countries using .htaccess with cloudflare

Blocking countries using .htaccess with cloudflare

Need to block users from a certain country from visiting your website using .htaccess but still want to keep using Cloudflare optimization services?

Just add this piece of code to your .htaccess

SetEnvIf CF-IPCountry IN BuzzOff=1
Order allow,deny
Allow from all
Deny from env=BuzzOff

In the above code, we are blocking all users from India(IN), replace IN with the country code of one you want to block.

2 thoughts on “Blocking countries using .htaccess with cloudflare

    1. Hello, the code works I have had it tested multiple times, but for it to work you must have the site traffic pass through cloudflare, did you maybe turn off that?

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.