Havenswift Hosting Ltd
All guides

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

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.

Other guides

Still stuck? Sign in and raise a ticket, and somebody will answer it.

Sign in