Block Visitors by Country Using htaccess

Blocking visitors by country using htaccess (Firewall) can be useful in case your blog/website is experiencing high volume of attack from particular country. It can also be very useful in case your website is experiencing DDOS attack from particular country.

For the example, we have tried to block China to browse website.

Access your htaccess file from you Cpanel. Add the below code to your htaccess files and save it.

<Limit GET HEAD POST>
order allow,deny
allow from all
deny from 1.0.1.0/24
deny from 1.0.2.0/23
deny from 103.240.124.0/22
</Limit>

To block all the visitor from particular country you need to find IP range of that country which you can get from ip2location website.

Leave a Reply

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