Dec 02, 2025
Elvinas S.
2min Read
This quick and easy tutorial will show you how to control site access based on visitors’ location. With some tweaks to the .htacess file, it’s possible to allow or block visitors from certain countries. Keep reading!

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

Fortunately, you can use your WordPress .htaccess file to allow or block visitors from specific countries. Let’s learn how to do so.
Plenty of online tools are available to allow or block visitors according to their country. In this tutorial, we’ll be using IP2Location.

Finally, paste the IP addresses of the countries you want to block or allow to .htaccess file. Here’s how to do it using Hostinger’s hPanel:

You can also use an FTP client to edit the .htaccess file.
Important! 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 find your IP address via What Is My IP Address
In this 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 IP2Location, then insert an ACL into your .htaccess file.
We hope that this guide was helpful. Let us know in the comments if you have any questions.

All of the tutorial content on this website is subject to Hostinger's rigorous editorial standards and values.