Blocking bad bots and unwanted traffic

Not all automated traffic is welcome. Some ignores robots.txt entirely, so blocking has to happen at the server.

Ask politely first

robots.txt is the correct first step and well-behaved crawlers respect it:

User-agent: BadBotName
Disallow: /

You can also ask for a slower crawl rate. Bots that ignore this need a firmer approach.

Blocking by user agent

In .htaccess:

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} (BadBot|AnotherBot) [NC]
RewriteRule .* - [F,L]

They receive a 403 and use almost no resources.

Blocking by address

Useful for a single persistent source, but most aggressive scraping comes from many addresses, so this is often a losing battle.

Identify before you block

Look at your raw access logs, or the visitor statistics in cPanel, to see which user agents are actually consuming your traffic. Blocking a bot you guessed at achieves nothing.

Be careful

  • Never block Googlebot or Bingbot unless you want to disappear from search.
  • Verify before blocking something claiming to be a search engine – bad bots frequently pretend to be Google.
  • Do not block by user agent so broadly that you catch real browsers.

Caching is often the better answer

A cached page costs almost nothing to serve. Good caching can make bot traffic a non-issue without blocking anything – and without the risk of blocking something you needed.

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to configure directory and file privacy

Password protection via .htaccess and .htpasswd It is possible to password protect an entire...

How to exclude a subfolder from password protection with htaccess file

A very useful and simple to use method of protecting access to a directory or an entire account...

Redirects: 301, 302 and how to set them up

A redirect sends a visitor from one address to another. Choosing the wrong type quietly costs you...

Common .htaccess mistakes

.htaccess is powerful and unforgiving. One wrong character takes the whole site down with a 500...