Cómo bloquear países por IP: restrinja el acceso a tu sitio web por países específicos usando .htaccess

How to block countries by IP: Restrict access to your website by specific countries using .htaccess

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.

Step 1: Generate the country IP addresses

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

  1. go to the home page of Country IP Blocks.
  2. Select the countries you want to block or allow.
  3. In the section select format , choose Apache .htaccess Deny either Apache .htaccess Allow. The choice depends on whether you want to block or allow visitors from those countries.
  4. Click on Create ACL .
  5. The ACL results They will appear on the right side of your screen. Press the button Copy ACL to clipboard.
  6. If you are using the function to allow , be sure to insert the line deny from all  which is above the list of allowed IP addresses.

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 into the file .htaccess