close

Offshoreserver distinguishes itself as the premier offshore hosting provider, renowned for its commitment to professionalism and innovation in service delivery.

close
close
ABOUT US AFFIALITES CONTACT US LOGIN CLIENT AREA
menu
+3197010282575 We also take care of providing excellent support 24/7 at no additional cost.

BLOGS

Limit Access to Your Website from Certain Regions Using.htaccess: How to Ban IP by Country

03.12.2023

You may easily restrict site access depending on the geographic location of visitors by following this short guide. The.htacess file can be modified to enable or deny access to users from particular nations.

Utilizing .htaccess to Allow or Ban Visitors From Certain Countries


After it is live, a website is accessible to everyone. But, it's sometimes vital to restrict access to your website, particularly when you wish to thwart spammers and hackers from specific nations.


Thankfully, you may allow or ban visitors from particular countries using the.htaccess file in your WordPress installation. Let's find out how to achieve it.

Create the country's IP addresses in step one.

There are several internet solutions available to allow or prohibit visitors based on their nation of origin. We'll be using country IP blocks in this lesson.

  1. Head to Country IP Blocks homepage.
  2. Select the countries you want to block or allow.
  3. On 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 those countries.click Create ACL.
  4. The ACL results will appear on the right side of your screen. Press the Copy ACL to Clipboard button.
  5. 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. 

  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 wiYou 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

You've learnt how to quickly restrict or permit visitors from particular nations thanks to this guide. All you have to do is use National IP Blocks to produce the country's IP address, then add an access control list (ACL) to your.htaccess file.

We sincerely hope this manual was useful. If you have any questions, please ask them in the comments section.