.htaccess to block countries

I recently updated my .htaccess file to block all countries from accessing my site yet it seems some are still getting through. It may be bots or should blocking countries using the .htaccess file block bots from those countries as well? I used the following to block each country (China here for example).

SetEnvIf CF-IPCountry CN BuzzOff=1

If you want to block countries on Cloudflare, you need to do this via firewall rules at https://dash.cloudflare.com/redirect?zone=firewall/firewall-rules.

1 Like

I’ve tried that. I still have multiple people accessing my site from the countries I’ve blocked.

The Block by Country firewall rule is pretty effective. What makes you think those countries are getting through? If they’re bypassing Cloudflare and going direct to your site’s IP address, you won’t be able to block them using any Cloudflare methods.

If people from these countries still manage to access your site after you have configured that rule, either your rule is incorrectly configured or they access your server directly and not via Cloudflare. In the latter case you need to make sure only Cloudflare IP addresses (cloudflare.com/ips) can access your server.

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.