Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

Blocking Visitors From Specific Countries

Restrict Access to Your Website from specific countries with .htaccess IP Blocking

 

Learn How to Restrict Access to Your Website from specific countries with .htaccess IP Blocking in Minutes! Unlock the Power of .htaccess to Allow or Block Visitors from Specific Countries. Let’s Dive In!

After going live, your website becomes globally accessible. Yet, there are instances where managing site access becomes imperative, particularly when safeguarding against spammers and hackers from specific regions.Fortunately, you can use your  .htaccess file to allow or block visitors from specific countries. Let’s learn how to do so.

Step 1: Generate the Country’s IP Addresses

Plenty of online tools are available to allow or block visitors according to their country. In this tutorial, we’ll be using IP2Location.

  1. Head to the IP2Location Firewall IP list tool.
  2. Select the country you want to block or allow.
  3. Choose between IPv4 and IPv6 in the IP Version menu.
  4. Choose the format in the Output Format menu. The choice depends on whether you want to block or allow visitors from those countries.
  5. Click Download.

    Generate the Country’s IP Addresses

  6. The tool will download the Access Control List (ACL) into your computer.
  7. 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. Open the ACL file on your computer, paste it to your .htaccess file, and hit Save. Your .htaccess file will look like this:

    Insert the Generated IP Addresses into the .htaccess File

    You can also use an FTP client to edit the .htaccess file.

 

 Restrict Access to Your Website from specific countries
Restrict Access to Your Website from specific countries with .htaccess IP Blocking

Conclusion :

Congratulations on mastering the art of controlling visitor access based on their country! By harnessing the power of IP2Location to obtain country-specific IP addresses and integrating ACL into your .htaccess file, you’ve gained valuable control over your website’s security.

We trust this tutorial has been enlightening. Should you have any queries or require further assistance, please feel free to drop us a message . We’re here to help!

 

Thank you for Contacting Lenawa Solutions , Please let us know in what we may assist you today :)

14:44