Opencart Security

How to Block a Country From Accessing My OpenCart Store?

Updated on: May 2, 2022

How to Block a Country From Accessing My OpenCart Store?

Cyberattacks are touching a new high every other day. Further, the e-commerce sector is among the worst-hit sectors. And OpenCart stores are not doing any better. Besides, it is always recommended to be safe than sorry.

Now, you can take different approaches to protect your OpenCart store. Most of which are listed in this extensive OpenCart security guide here. One of the ways that we are going to discuss today is – OpenCart country blocking.

Blocking countries, where your store is not relevant is one of the most effective ways to cut down on –

  • cyberattacks,
  • superfluous traffic, and
  • server bandwidth expense.

For example, you are running an apparel business but you only deliver to limited countries. In such a case, restrict other countries that can access your OpenCart store.

Even if you run a global e-commerce store, blocking the notorious countries is only going to add to your business’ safety.

3 Approaches to Do OpenCart Country blocking

1. OpenCart Country Blocking With a Click

If you are not a very technical person then Astra Firewall is the right choice for you. Here is how you can use the Astra Firewall to block a country from accessing your OpenCart store:

  1. Log into your Astra dashboard.
  2. Go to the ‘Threats’ tab
  3. Navigate to the section that says ‘Add a custom rule’.
  4. Just type in the country you wish to block.
  5. Click on the ‘Block’ button and it’s done!

Astra Firewall also provides you an option to whitelist the countries. To whitelist countries from the Astra dashboard do the following:

  1. Log into your Astra dashboard.
  2. Go to the ‘Threats’ page.
  3. Navigate to the section that says ‘Add Custom Rule’.
  4. Just type in the country you wish to whitelist.
  5. Click on the ‘Trust’ button and it’s done!
Astra Firewall Country Blocking
Astra Firewall Country Blocking

2. OpenCart Country blocking via .htaccess

The .htaccess file is a very important file for your store configuration. OpenCart country blocking via .htaccess requires access to cPanel or FTP account in order to proceed with the following steps:

Step 1: Generate IP addresses of the countries you want to block.

Generating IP list for Country Blocking
Generating IP list for Country Blocking (Source:
  1. Visit or any other site that generates a complete list of IP addresses of the country.
  2. Select the ‘country’ or the whole ‘continent’ that you want to block.
  3. Next from the list of formats, select ‘Apache .htaccess Deny’.
  4. After you are finished with the selections, click on ‘Create ACL’ button. The generated list will be used for country blocking in OpenCart.

Step 2: Embedding the content of generated list into .htaccess file

  1. The .htacces file can be accessed by navigating to public_html directory. This can be done by going through File Manager in cPanel or connecting to your account by File Transfer Protocol client.
  2. Once you are able to access the .htaccess file, the IPs from the list should be included in it.
  3. To include them simply select all, copy and into the .htaccess file.
  4. Save the file and you are done.

3. OpenCart Country Blocking via GeoIP Module

OpenCart GeoIP module helps you to block country or the whole continent from accessing your store. This module also provides you with an option either to redirect the blocked users to any other relevant link or display the custom message.

Vice-a-versa, it also allows you to whitelist the IP addresses of the users you want to allow access to your store. Using OpenCart GeoIP module you can simply block that country by following the steps below-

  1. Install the GeoIP extension.
  2. Navigate to Rule Information.
  3. Open Country List and select the countries or whole continent to block the access from visiting your website.
  4. Save the settings and you are done.
Country List in GeoIP Module


If you are an online store owner then there are a number of threats that can keep you awake at night. These threats can be DDoS attacks, website scraping, bad bots, and so on. So it becomes a necessity to protect your stores from such attacks for maintaining your brand reputation.

And knowing your target customers can really help to achieve this. It will allow you to block the users who are not relevant to your store based on location and help you minimize your footprint.

Lastly, let us know in the comments if you found the post helpful.

Was this post helpful?

Aakanchha Keshri

Aakanchha is a technical writer and a cybersecurity enthusiast. She is an avid reader, researcher, and an active contributor to our blog and the cybersecurity genre in general. To date, she has written over 200 blogs for more than 60 domains on topics ranging from technical to promotional. When she is not writing or researching she revels in a game or two of CS: GO.
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments

Psst! Hi there. We’re Astra.

We make security simple and hassle-free for thousands
of websites and businesses worldwide.

Our suite of security products include a vulnerability scanner, firewall, malware scanner and pentests to protect your site from the evil forces on the internet, even when you sleep.

earth spiders cards bugs spiders

Made with ❤️ in USA France India Germany