How to Block Country Traffic in cPanel?

Preventing specific visitors from accessing your website to avoid conflicts or complications is essential. Regular cPanel users can achieve this by blocking web traffic from a particular country on their hosting through the following steps:

How to Block Country Traffic:

  1. Log in to your cPanel account.

  2. Use the File Manager tool to edit the .htaccess file.

  3. Finish the file with the following lines:

 

RewriteEngine on RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^US$ 

RewriteRule ^(.*)$ – [F,L] 

Note: The provided example uses the country code "US" for the United States. You can find the country codes you need at ISO 3166-1 alpha-2 link.

  1. Click on "Save Changes and Close."

https://www.milesweb.in/hosting-faqs/wp-content/uploads/2021/11/cp_block_country_traffic.png

By implementing this process, cPanel will screen the traffic from the designated country you choose to block. This implies that the server will automatically deny any access requests originating from the blocked country, resulting in users receiving a 403 forbidden error.


Was this article helpful?

mood_bad Dislike 0
mood Like 0
visibility Views: 144