Do you have a website or blog that you want to block visitors from certain locations to access it? There are so many reasons you may consider to do that. No matter what is your reason, this article will help you do that for free.

If you can edit a .htacess file of your website, then it’s possible to allow or block visitors from certain countries. Can you get access to your own and edit it? If yes, then you can block visitors from certain locations on your website. But first, you need to use IP addresses. So as a result of this, we are going to pass through two steps; how to get IPs of locations or countries you want to block and how to insert the generated IP addresses into the .htaccess file of your website.

Now, let’s start to do so. You may see our guide on how to clean a hacked website with WordFence for free.

How to block visitors from certain locations from accessing your website

Step 1: Generate the location’s IP addresses

An Internet Protocol (IP) address is a numerical label (example; 192.0.2.1) that is assigned to a device connected to a network for communication. IP addresses serve two main functions: network interface identification, and location addressing.

There are different tools online to use to allow you see every IP address assigned to different locations in different country. In this article, we’ll be using IP2Location.

Now, let us show you how to generate IP address of any location you want to block visitors of from accessing your website

  1. Visit IP2Location Firewall IP list tool.
  2. Select the country you want to block or allow.
  3. Choose between IPv4 and IPv6 in the IP Version menu.
  4. Choose the format in the Output Format menu (the choice depends on whether you want to block or allow visitors from those countries).
  5. Click Download.
How to generate IP address of any country using IP2location tool
  1. After that, you have Access Control List (ACL) downloaded in your computer.

Step 2: Insert the Generated IP Addresses into your websites .htaccess File

Now, you can paste the IP addresses of the countries you want to block or allow into the .htaccess file of your website. Here’s how to do it via cPanel:

  1. Open your cPanel and go to Files section and click File Manager.
  2. Navigate to the public_html folder or hit the domain name that you want to work on if you have multi domain names hosted on your cPanel
  1. Right click the .htaccess folder and click edit which will open in a new tab where you will enter IP addresses you want to block or allow.
  1. Open the file which you downloaded from the IP2location on your computer, copy it and paste it to your website .htaccess file, and hit Save.
  1. Your .htaccess file after pasting the list of IP addresses which you want to block will look like the screen short above.

Note that you can also use an FTP client to edit your website .htaccess file.

Conclusion

We hope that this guide was helpful. Let us how you feel via the comment section if you have any question. You may see our expert step-by-step guide on how to remove viruses on your website via cPanel.

If you know that this article has helped you know how to block visitors from certain locations or countries from accessing your website, then please subscribe to my YouTube channel or like my Facebook page for more update.

In conclusion, if you do not want to allow some visitors to use your website, what to do is to simply know the location’s IP address. You can use IP2Location which will generate for you IP addresses of any country in the world for you to insert the one you like into your website .htaccess file.

Abdulrazaq Yahaya

On this blog, I share articles on how to develop your personal and career life. I would like to hear your feedback via the comment box below.

This Post Has 3 Comments

  1. Ibraheem Baba

    Hi sir, what if I do not want to block the entire country but state or region, how can I do?

  2. Fidelix Georges

    I enjoyed this guide. It is good for people who want to block hacker or attackers on their website. I will recommend it to my web manager to read it.

Leave a Reply