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.
.htaccessfile is located in yourpublic_htmldirectory. You can open it up usingFile Managerin yourControl Panelor 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 onthis 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.
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 downCTRL+A(MAC usersCommand+A) to select all data, then hold downCTRL+C(MAC usersCommand+C) to copy. When finished paste your data into your .htaccess file usingCTRL+V(MAC usersCommand+V).