Posted on September 5, 2019
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 Control Panel or FTP account
Step 1 — Opening up your .htaccess file.
.htaccess file is located in your public_htmldirectory. You can open it up using File Manager in your Control Panel or by connecting to your account via FTP Client (FileZilla, for example).
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.
- Select a country that you want to either block or allow.
- You can select a list that would be ready to copy and paste directly to .htaccess file.
- Click Create ACL.
Step 3 — Copying generated list into .htaccess file
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).