How to Allow or Block Visitors From Specific Countries Using .htaccess

If you have noticed that you are being attacked from a specific country or simply want to deny or allow access to your website from one or more countries you can use .htaccess file to easily do that. This tutorial will show how to use .htaccess to block IP of visitor from the specific country.

What you’ll need

Before you begin this guide you’ll need the following:

  • Access to cPanel or FTP account

Step 1 — Opening up your .htaccess file.

.htaccess file is located in your public_html directory. You can open it up using File Manager in your cPanel or by connecting to your account via FTP Client (FileZilla, for example). The following tutorials describe both methods in detail:

Step 2 — Generating a list of IP addresses that you want to block

You can generate a list of IP addresses from a specific country on this website.

Generate IP list

  1. Select a country that you want to either block or allow.
  2. You can select a list that would be ready to copy and paste directly to .htaccess file.
  3. Click Create ACL.

Step 3 — Copying generated list into .htaccess file

IP list

As it is suggested on the website – to copy the above data, click within the country list, hold down CTRL+A (MAC users Command+A) to select all data, then hold down CTRL+C (MAC users Command+C) to copy. When finished paste your data into your .htaccess file using CTRL+V (MAC users Command+V).

IMPORTANT! If you are no longer able to access your website check if your IP is not on the block list. You can find your own IP address at


This tutorial shows how easy it is to block or allow a specific country from accessing your website using an .htaccess file.

About the author

Elvinas S.

Elvinas is a senior server administrator at Hostinger. He monitors the infrastructure’s well-being and keeps the uptime at a maximum. Besides server management, web development has always been one of his biggest passions.

Add Comment

Click here to post a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get Exclusive Content

Join thousands of webmasters who get our free newsletter with tips on how to drive more traffic and revenue to their websites!

Please wait...

Thank you for sign up!