Preventing specific visitors from accessing your website is essential to avoid conflicts or complications. Regular cPanel users can block web traffic from a particular country through their hosting by following these steps.

How to Block Country Traffic

  1. Step 1: Log in to cPanel

    Access your cPanel account using your credentials.

  2. Step 2: Open File Manager

    Use the File Manager tool to locate and edit the .htaccess file.

  3. Step 3: Add blocking rules

    Add the following lines to the end of your .htaccess file:

    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.

  4. Step 4: Save changes

    Click on "Save Changes and Close."

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