Skip to content

Block Unwanted Countries Refuse Countries Access To Your Site

  • 2 min read
Block Unwanted Countries Website Access

A pro reason to block unwanted countries is to save bandwidth, especially on video sites and music streaming sites but sometimes it can be for security and privacy reasons. Speed up your website and avoid spam when you block unwanted countries. For Example, if you were running services like speed test Ookla but only wanted users from one country using the tool then you could use these htaccess rules to block countries.

Block unwanted countries to save bandwidth/spam and other reasons.

There are many reasons why you may want to block visitors from a certain country. It could be that they are just wasting your bandwidth or for security reasons.

People may want to block geographical regions from accessing their websites. Other reasons are spamming and attacks so it’s a security measure also. But mostly because the traffic from some countries is of no benefit to your website. Allowing these visitors are just wasting bandwidth and making your site load slower for your real target country.

Block unwanted countries using the htaccess file.

Blocking visitors from regions that are useless to your website. This can be easily done using the Htaccess file. What you will need to know is the IP range that the visitors are arriving on your site from in order to deny them.

To get the IP address of all the countries that you may wish to block from your server. This may sound like much work. But on this site you can block a country, block by IP address, or deny access by country. You will select which countries you wish to block. Next, they will auto-generate the code for you. Then and all you need to do is paste the code into your Htaccess file.

Here is an example of How to block visitors from Antarctica for example.

The code can be generated by ip2location or you can find the IP address by country here on Wikipedia.

# -------------------------------------------------------
# Free IP2Location Firewall List by Country
# Source: https://www.ip2location.com/free/visitor-blocker
# Last Generated: 31 Jan 2021 21:10:15 GMT
# [Important] Please update this list every month
# -------------------------------------------------------
<Limit GET HEAD POST>
order allow,deny
allow from all
deny from 156.0.201.0/24
</Limit>

This will give unwanted visitors an ErrorDocument 403 Forbidden to keep your website traffic only from the countries you are targeting saving bandwidth or reducing spam. Or in the case of Youtube, You will get this notice.

Youtube Blocked by Country
Blocked Access By Country on Youtube