Block your network from countries

New Page

htaccess

August 23, 2022

Elvins S.

2 minute read

How to block IP by country – Restrict access to your website from specific countries using .htaccess

Copy link

Copy!

Download the eBook: Speed ​​Up Your Website. 8 practical tips that work

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

Allow or block visitors from specific countries using .htaccess

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

Fortunately, you can use your WordPress .htaccess file to allow or block visitors from specific countries. Let’s learn how to do it.

Step 1: Generate country IP addresses

There are many online tools available to allow or block visitors depending on your country. In this tutorial, we will use country IP blocks .

  1. Go to the Country IP Blocks home page.
  2. Select the countries you want to block or allow.
  3. In 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 these countries.
  4. Click Create ACL .Create ACLs using country IP blocks Create an Access Control List Using Country IP Address Blocks
  5. Los resultados de ACL aparecerán en el lado derecho de su pantalla. Press the botón Copiar ACL al portapapeles .Allow or Block Countries Using Country IP Blocks Allow or Block Countries Using Country IP Blocks
  6. If you are using the allow function, make sure to insert the line deny from all  above the list of allowed IPs.

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 .htaccess file. Here’s how to do it using Hostinger’s hPanel:

  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. Your .htaccess file will look like this:Allow or block countries using .htaccess file Allow or block countries using .htaccess file

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

Conclusion

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 Country IP Blocks, then insert an access control list (ACL) into your .htaccess file.

We hope that this guide was helpful. Let us know in the comments if you have any questions.

Was this tutorial helpful?

Yes

No

Author Author

The author

Elvinas S.

Elvinas is a senior server administrator at Hostinger. He monitors the infrastructure’s well-being and keeps the uptime at a maximum. Besides server management, web development has always been one of his biggest passions.

More from Elvinas S.

Top 10 Hacker Countries to block in your Firewall

What are the most toxic hacker active countries?

A toxic hacker attack on your network has a list of top 10 origin countries.

The types of attacks can vary.

There are different types of attackers such as background attacks coming from worms or robots.

They are often looking for a few known vulnerabilities scanning millions of IPs until they find an open system to attack.

Afterwards it will infect the target and include it in a botnet.

There can also be other types of attacks where it is moving more into the criminal aspect.

This can be where experienced hackers get together and form a group.

Professional Criminal Hacker Gangs

Luego, a escala profesional, persiga a las grandes empresas para entrar y robar datos.

Luego will require a rescate de millones para no divulgar la información al público.

Los ransomware attacks cuestan a las empresas, el sector público, como los gobiernos y los hospitals, miles de millones de dólares estadounidenses en pérdidas al año.

It is recommended to start implementing strong anti-hacking measures to prevent ransomware attacks.

1 – Russia

Often from here we see gangs of professional hackers hunting victims and then blackmailing them.

They have been accused of being a haven for ransomware gangs as long as they are not hacked in their own country.

 

2-Chinese

A large number of automated robotic worms are emerging from China to add victims to botnets.

 

3 – Turkey

Here we see gangs of professional hackers growing.

They tackle SQL injection flaws to quickly compromise a target in order to steal data.

 

4 – Brazil

Botnet activity and automated scans.

 

5-Bangladesh

Low-level vulnerability scanners.

 

6-Pakistani

Scanners for common vulnerabilities that most victims have in the medium-low risk category.

 

7-India

It is not only limited to hacking activities but also a large number of call center scams.

Where they call people and get them to send them money.

 

8-Nepal

Much of the botnet activity originates here.

 

9 – Romania

Romania is popular with hacker gangs, there was even a TV show called Hackerville about it on HBO since 2018.

 

10 – Afghanistan

More of the type of botnet activity


Video Block your network from countries

Related Posts

Free chat room code for my website

Contents1 How to set up a free chat room on the website.2 3 comentarios2.1 Trackbacks/Pingbacks2.2 Submit a Comment Cancel reply3 How to Create a Chat Room Website…

Background image full screen css

Contents1 Cómo – Full Page Image1.1 Example1.2 Example2 CSS background image tamaño tutorial: how to codify a complete page background image3 Perfect Full Page Background Image3.1 Méthode CSS géniale,…

WordPress leverage browser caching

Contents1 Aproveche el almacenamiento in hidden del navegador1.1 Will it works for my website?1.2 Where are plugin options1.3 Some JavaScript files still display under Leverage Browser Caching1.4…

WordPress post to facebook page

Contents1 How to Automatically Post to Facebook from WordPress1.1 Download Now: How to Launch a WordPress Website [Free Guide + Checklist]1.2 1. Create an IFTTT account.1.3 2….

Download images from wordpress media library

Contents1 How to export your WordPress media library1.1 Download maintenant : How to launch a WordPress website [Free Guide + Checklist]1.2 How to export your WordPress media…

WordPress single post template

Contents1 How to Create Custom Unique Post Templates in WordPress2 Post Template Files2.1 author.php2.2 Fecha.php3 Handbook navigation4 How to Create Custom Single Post Templates in WordPress5 Video…