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

Block bad bots from Apache in WHM and cPanel

Some bots visit your site only to steal content or slow it down. This guide shows how to block them.

SSL and Security2 min read14 steps5 screenshots

What is a bot?

A bot is a program that visits websites by itself. Good bots, such as search engine bots, help people find you. Bad bots scrape content, hunt for weak spots or flood your site with requests. Apache is the software that serves your website pages. A user agent is the name a bot gives itself when it visits. You can block bots by that name.

Find the bad bots first

  1. Log in to cPanel.
    Screenshot: Log in to cPanel.
  2. Open Metrics then Raw Access, or Visitors.
  3. Download the log and look for names or IP addresses that appear very often.

An IP address is a number that identifies a computer on the internet.

Block by user agent using .htaccess (cPanel)

  1. Open File Manager and go to public_html.
  2. Click Settings and tick Show Hidden Files (dotfiles).
  3. Download .htaccess as a backup.
  4. Right-click it and choose Edit.
  5. Add these lines, using the real bot names:
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} (BadBot|EvilScraper) [NC]
RewriteRule .* - [F,L]

These lines return a "403 Forbidden" answer to any visitor whose name contains one of the listed words. NC means the case does not matter.

  1. Click Save Changes and test your site.

Block an IP address

In cPanel, open IP Blocker. Type the address and click Add.

Block for the whole server in WHM

This needs WHM access, for resellers with the right rights, VPS and dedicated owners.

  1. Log in to WHM.
  2. Search for Apache Configuration and open Include Editor.
    Screenshot: Search for Apache Configuration and open Include Editor .
    Screenshot: Search for Apache Configuration and open Include Editor .
    Screenshot: Search for Apache Configuration and open Include Editor .
    Screenshot: Search for Apache Configuration and open Include Editor .
  3. Choose Pre Main Include for all versions.
  4. Paste a rule block that blocks the user agents. Save.
  5. WHM checks the syntax and restarts Apache.

Warning: wrong rules can stop all sites on the server. Keep a copy of what was there before.

Tip: Never block names like Googlebot or Bingbot unless you want to disappear from search. Need help? Open a ticket.

Quick recap

  • Bad bots can steal content and slow your site.
  • Find them in your access logs.
  • Block by user agent in .htaccess or by IP in IP Blocker.
  • Use the WHM Include Editor for server-wide rules.
  • Back up before editing.