Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Block visitors from a country in cPanel

You can stop visitors from chosen countries from opening your website. This guide shows how, using the .htaccess file.

SSL and Security2 min read8 steps1 screenshots

Why block a country?

Some sites get many fake visits or spam from places where they have no real customers. Blocking those places can reduce spam and server load. Be careful. Real visitors, and tools such as search engines, may also come from those places.

What is .htaccess?

.htaccess is a small settings file for your website. The server reads it before it shows a page. You can put rules there, such as "do not let this address in".

cPanel has no simple country button. You block a country by blocking its IP address ranges. An IP address is a number that identifies a computer on the internet. Country lists of IP ranges are published by several websites. Search for "country IP ranges" to get the list you need.

Steps

  1. Log in to cPanel.
  2. Open File Manager.
  3. Go to public_html. Click Settings at the top right and tick Show Hidden Files (dotfiles). Click Save.
  4. Right-click .htaccess and choose Download to keep a backup copy.
  5. Right-click .htaccess again and choose Edit.
  6. Add your rules at the end of the file. Example for two ranges:
<RequireAll>
Require all granted
Require not ip 203.0.113.0/24
Require not ip 198.51.100.0/24
</RequireAll>

These lines allow everyone except the listed IP ranges. The numbers shown are only examples. Replace them with the real ranges.

  1. Click Save Changes.
    Screenshot: Click Save Changes .
  2. Open your site to check that it still loads.

Warning: a typing mistake in .htaccess can cause a "500 error" and take the site down. If that happens, restore your backup copy.

Other options

  • Open IP Blocker in cPanel to block single addresses or ranges.
  • Use Cloudflare or a security plugin that blocks by country. Ask Hostvento support whether these fit your plan.
Tip: Rule syntax can differ on older servers. If the code above gives an error, ask support through a ticket.

Quick recap

  • Blocking a country means blocking its IP ranges.
  • Back up .htaccess before you edit it.
  • Add the rules in File Manager and save.
  • Test your site right after.
  • Remember that real visitors may be blocked too.