Home Web Design & Development SEO Services Mobile App Development Digital Marketing Video Animation Blogs Our Works Contact Us Write For Us

Quick Enquiry

How To Block or Allow Website Users From a Specific Country Using .htaccess

The Best Web Development Agency in UAE

web design agency dubai

How To Block or Allow Website Users From a Specific Country Using .htaccess

This quick and easy tutorial will show you how to control your site access based on visitors location. With some tweaks to the .htacess file, it is possible to allow or block visitors from certain countries.

Once launched, a website is available worldwide. But in many cases, it is necessary to control your site access, especially when you want to stop spammers and hackers from particular countries.

Fortunately, you can use your website server or wordpress .htaccess file to allow or block visitors from specific countries. Let’s learn how to do so.

Step 1: Generate the Country IP Addresses

Plenty of online tools are available to allow or block visitors by the country. In this tutorial, we will be using Country IP Blocks.

1.  Head to Country IP Blocks homepage.

2.  Select the countries you want to block or allow.

3.  For the Select Format section, choose Apache .htaccess Deny or Apache .htaccess Allow. The choice depends on whether you want to block or allow visitors from those countries.

4.  Click Create ACL.

5.  The ACL results will appear on the right side of your screen. Press the Copy ACL to Clipboard button.

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

Finally, paste the IP addresses of the countries you want to block or allow to your .htaccess file. To do this,

1.  Go to Files -> File Manager.

2.  Select your domain and hit Go to File Manager.

3.  Navigate to the public_html folder and double-click the .htaccess file.

4.  Paste ACL to your .htaccess file and hit Save & Close.

You can also use an FTP client to edit the .htaccess file.

If you cannot access your website after inserting the generated IP addresses, check whether your IP address is included on the block list. You can see your IP address via What Is My IP Address


In this basic tutorial, you’ve learned the easy way to block or allow visitors from specific countries. All you need to do is generate the country’s IP address via Country IP Blocks, then insert an access control list (ACL) into your .htaccess file.

  Jan 27, 2021     by Hostinger     323 Views     0

Share This Post :



to comment

© Copyright The Watchtower 2010 - .

© Copyright The Watchtower 2010 - .