Web Hosting: Geo Blocking / Block or Allow Website Access From Specific Countries in cPanel

Modified on Wed, 22 Feb 2023 at 03:43 PM

Website owners may want to block or explicitly allow traffic coming from certain countries. Blocking countries may be used to help curb unwanted malicious activity coming from those countries. This article will go over ways to control website country access with our web hosting, which can be done by modifying the .htaccess file, or using a WordPress plugin.


Additionally, various forms of malicious activity are automatically defended against by the free built-in security tools of "Imunify360" and "ModSecurity". More info about security on our web hosting can be found in this HelpDesk article: Web Hosting: Security (Account, cPanel, Email)




Modify the .htaccess file to block or allow specific country access


  • Go to https://www.countryipblocks.net/acl.php
  • Select the Continents and/or Countries you would like to block or allow
  • Select the format of "Apache .htaccess Deny" to deny access from those places, or select "Apache .htaccess Allow" to explicitly allow access from those places. To only allow access from one place and deny everything else, something like what can be found in this question and answer may work: https://stackoverflow.com/questions/4400154/deny-all-allow-only-one-ip-through-htaccess
  • Click "Create ACL", then the text will be generated on the page, which you can copy and paste into the .htaccess file, 
  • Next, Login to cPanel
  • Go to the cPanel "File Manager"
  • Go to the file directory where your website is housed. For the primary domain, this will be the folder "public_html". For addon domains, it will be a folder with the domain name (such as "example.com"), or will be the folder name you chose when creating the addon domain.
  • On the top right of the page, click on the "Settings" button.
  • Check-mark the box that says "Show Hidden Files (dotfiles)"
  • Click "Save"
  • Find the .htaccess file on the page. If there is a long list of files, you can sort them by name, with .htaccess being near the top as the file name starts with a dot. To find the file, you can also use the browser page search tool ("Ctrl + F" for Windows, "Command + F" for Mac) to search for the ".htaccess" file name on the page.
  • Right-click on the .htaccess file, and choose "Edit", then click "Edit" again on the popup to go into the text editor.
  • Paste the previously generated IP address list at the bottom of the .htaccess file
  • Click "Save Changes" in the top right of the page. The new configuration takes effect immediately.



Use A WordPress plugin to block or allow specific country access


You can use WordPress plugins such as "IP2Location Country Blocker" to block specific country access to your WordPress website. These plugins can be searched for and installed directly from your WordPress admin area, in the "Plugins" section. Info about how to install WordPress plugins can be found here: https://www.wpbeginner.com/beginners-guide/step-by-step-guide-to-install-a-wordpress-plugin-for-beginners/







Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article