Below is where you add the countries you wish to ban
When you have a website, you want to bring in as much traffic as possible, but sometimes, you find a few bad actors out there that don't necessarily have the best of intentions. In times like these, you have the option to protect your site by blocking individuals who you deem malicious. You not only have the ability to block a single IP, but you can also do several or even whole countries. The steps in this article will walk you through adding these blocks to your .htaccess file.
Editing .htaccess file
1. Log into cPanel. Once you are in, select File Manager
2. Navigate to your document root, which is the Public_HTML directory.
3. To be able to view the .htaccess
navigate to the upper right-hand corner click on Settings
In your preferences, select the document root for the domain you wish to edit and click on Show Hidden Files in your preferencesSelect.
4. In your domain's document root, select the .htaccess file and click Edit in the upper toolbar.
5. Once you're in the editor, you can add a block like below to ban a single host where you replace the XXX for octets of the IP address.
order allow, deny deny from XXX.XXX.XXX.XXX/32 deny from XXX.XXX.XXX.XXX/32 allow from all
6. To ban based on country codes, add a block like below. In this example, we used the United States (US), Canada (CA), and Mexico (MX).
\ GeoIPEnable On
Below is where you add the countries you wish to ban
SetEnvIf GEOIP_COUNTRY_CODE US DenyCountry SetEnvIf GEOIP_COUNTRY_CODE CA DenyCountry SetEnvIf GEOIP_COUNTRY_CODE MX DenyCountry Allow from all Deny from env=DenyCountry