Once you launch your website, it is immediately available to most of the world. The Internet is, by default, a global place for commerce and information. Still, as the owner and operator of your website, you may wish to disallow specific countries to have access to your site. The biggest reason people want to block a country is due to a high number of attacks coming out of it. You also may simply not want to do business with a specific country.

Whatever your reason, you can block a country by editing the htaccess file and setting it to deny its IP ranges. Below are the instructions for performing this task.

How to block a country's IP ranges in .htaccess

  1. The first thing we need are the IP ranges you wish to block. A visitor-blocker generator is available at IP2Location.com. This tool is free to use. It allows you to create a text file with the code you will need. The country we chose for our sample is North Korea, due to its small number of IP ranges for demonstration. The output format chosen for the code is Apache .htaccess deny.
  2. Now that you have the file downloaded to your computer, you will need to log into the cPanel dashboard.
  3. Once inside the cPanel, enter the File Manager tool and locate your htaccess file for editing.
  4. Once you open the .htaccess file editor, paste the code for blocking the country inside at the top of the file. Below is an example of how the code looks for North Korea.

    <Limit GET HEAD POST>
    order deny,allow
    deny from
    deny from
    deny from
    deny from
    deny from
    deny from
    deny from
    deny from
    deny from
    deny from
    deny from
    allow from all
  5. Once you enter the code, click on the Save Changes button to activate the .htaccess and begin to block the country. Any IP addresses within these ranges will receive an access denied message.
Did you find this article helpful?

We value your feedback!

Why was this article not helpful? (Check all that apply)
The article is too difficult or too technical to follow.
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
How did you find this article?
Please tell us how we can improve this article:
Email Address

new! - Enter your name and email address above and we will post your feedback in the comments on this page!

Did you find this article helpful?

Post a Comment

Email Address:
Phone Number:

Please note: Your name and comment will be displayed, but we will not show your email address.

Related Questions

Here are a few questions related to this article that our customers have asked:
Would you like to ask a question about this page? If so, click the button below!
Need More Help?

Help Center Search

Current Customers

Email: support@WebHostingHub.com Ticket: Submit a Support Ticket
Call: 877-595-4HUB (4482)
757-416-6627 (Intl.)
Chat: Click To Chat Now

Ask the Community

Get help with your questions from our community of like-minded hosting users and Web Hosting Hub Staff.

Not a Customer?

Get web hosting from a company that is here to help.