How can I block specific countries accessing Magento 2 site?

  • please explain breifly May 27, 2019 at 5:47

2 Answers 2


You can block access to specific countries either in .htaccess or free Magento extensions available

  1. Find the reliable list of IP's for the country you want to block from IP2location

    1: https://www.ip2location.com/free/visitor-blocker. Input the country name and generate the IP's list for the country you want to block. Open the .htaccess file and copy the code from downloaded file similar to the lines below

    order deny,allow deny from deny from deny from  allow from all

Save the changes and the IP's from these countries will be denied access to Magento store.

  1. Else use this free extension to configure the countries to be blocked in the backend so the module does other work to restrict access for specific countries https://www.mageworx.com/geo-lock-magento2-extension.html
  • blocking countries in application or http web server is a bad idea, firewall is the proper place for this task.
    – MagenX
    May 27, 2019 at 8:12

Every country is assigned a range of IP addresses. You can allow or deny your website from being accessed from a specific IP or a list of IP addresses by using the .htaccess method.

Not the answer you're looking for? Browse other questions tagged or ask your own question.