Need help? Chat now!
Search results for:
Table of Contents
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
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.
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).
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
Below is a comprehensive list of country codes.
Written by Hostwinds Team / April 24, 2018