Obviously when you are the owner of a website, you’d want to allow visitors from all over the world to access your website. However, there are times when there is a need to block visitors from some countries on a certain webpage or vice versa. One good example is when you host a local contest online and you only want people from your own country to participate. Allowing visitors from your country while blocking the rest is the way to go, so there is no need to manually prune ineligible participants when choosing the winner. If you don’t have a powerful server that can handle the load created by unknown or unimportant bots, it is also best to temporarily block them from accessing your website.
The easiest way to block visitors from a country is by using .htaccess because we can do it ourselves through FTP without installing or messing with the iptables firewall rules. Here we have different places to obtain a generated country IP list in CIDR format for free and another method using a cloud-based web application firewall.
An important note if you want to block visitors by country using htaccess. Make sure you periodically generate a new list because the IP address database changes from time to time or else you might either miss or wrongly block visitor from other countries.
(more…)
