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.
- 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).
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 whatismyipaddress.com.
This tutorial shows how easy it is to block or allow a specific country from accessing your website using an .htaccess file.