# AI Ban Hammer

> Source: <https://yunzi.co.uk/ai-ban-hammer/>
> Published: 2026-11-24 18:52:00+00:00

**Recommendation:** Block bots that ignore robots.txt by logging honeypot-path IPs with Apache SetEnvIf/CustomLog and reloading them as a RewriteMap to return 402, avoiding PHP and unbounded .htaccess growth.
More in the playbook "Securing agents and AI tools": <https://wpnews.pro/playbooks/agent-security>

I hate myself just a little bit for writing about AI. Generally I’m sick of the smallweb’s twin addictions of writing ‘blogging is great isn’t it’ posts and writing (for or against) fucking AI. That said, I’m going to, because its my blog and I liked this method I found of blocking some AI bots that behave badly.

I’m plagiarising a lot of people here, so basically very little of this is my own work and I take no credit for it. I’ll try to give credit where I can, but please forgive me if I forget. Ideas initially started to form after reading the post on [Terence’s site](https://shkspr.mobi/blog/) about how he’d used a PHP script that robots.txt meant should never be executed. Should a bot ignore robots.txt then the script added its IP address to a .htaccess file to block any further requests and give a ‘402’ (Payment Required) as the standard HTTP web responses to not (yet) have a HTTP 469 ‘Fuck off Clanker’ response. Although I’m hoping for one soon.

I implemented [Terence’s solution](https://shkspr.mobi/blog/2026/11/blunt-banhammer-blocks-basic-bots-ballistically/) with my own named folder and every so slightly modified PHP script and let it run for around 24 hours. It caught a few bots including something that was at least reporting itself to be Meta operated. As I’d not waited any significant time after updating robots.txt I can perhaps give Zuckerberg the benefit of the doubt here. After 24 hours I decided I didn’t like this solution. I don’t especially want PHP and Apache-PHP on my server after the last critical security holes cost me several days of pain at work and I could see problems with DDOS and huge .htaccess files, so started investigating alternatives.

Anubis [https://anubis.techaro.lol/](https://anubis.techaro.lol/) of course which acts as a proof of work test for bots or something like Iocaine [https://iocaine.madhouse-project.org/](https://iocaine.madhouse-project.org/) which is more devious. I don’t especially want to play with the bots (although it has some temptation), I just want to stop the things from stealing my intellectual property especially when I’ve expressly told them not to in robots.txt. I realise robots.txt is convention, rather than enforcement, but its very very irritating that actors including ChatGPT (who I caught doing this) decide to just ignore it so they can do whatever they like.

A commentator on the same post of Terence’s called Armin Wolfermann came up with a way of configuring the Apache web server to basically write a log file of IP addresses that try to access a robots.txt forbidden directory then load that file back into Apache as a RewriteMap file so all requests coming from those IP addresses would then be blocked. I changed things ever-so slightly to keep the 402 Payment Required response simple because that amuses me more.

So first, setup robots.txt to stop bots from trying to access a certain directory;

```
User-agent: *
Disallow: /badplace/
```

Then configure Apache for my website to write out the IP addresses that ignore robots.txt and try to touch me in the the badplace;

```
LogFormat "%h %{honeypot}e" honeypot_logformat
CustomLog "/var/place/to/log/things/mybadplacelog.txt" honeypot_logformat env=honeypot
SetEnvIf Request_URI "/badplace/" honeypot=1
```

Then add rules for Apache to load the file in and do something extra to those requests;

```
RewriteEngine on
RewriteMap honeypot "txt:/var/place/to/log/things/mybadplacelog.txt"
RewriteCond ${honeypot:%{REMOTE_ADDR}|0} =1
RewriteRule ^ - [R=402,E=!honeypot,L]
```

If you’d just rather stop them with a 403 error;

```
RewriteRule ^ - [F,E=!honeypot]
```

But if using 402 (or other error code) you can set your own special message;

```
ErrorDocument 402 "No no no - you didn't say the magic words - no no no"
```

To bait the hook and add the link to pages on my website I went back to Terence’s initial work.

Include this HTML

```
<a id="honey" aria-hidden="true" href="https://yunzi.co.uk/badplace/">‍</a>
```

and this CSS

```
#honey {
    display: none !important;
    cursor:  none !important;
}
```

Been quite interesting seeing the logs for the IPs that have been captured. Several have very clearly been AI bots that just don’t give a stuff for robots.txt. At least one was Chinese but that’s not new. When this blog was on Bear, the Chinese seemed particularly interested in one single post… Not entirely sure why that one but anyway. Perhaps the Peoples Republic are fascinated in the 20th century defences lost under hedges in the UK, who knows. Some have been more puzzling, several that ONLY request the blocked directory with no other requests before or after from the IP. Suggesting something has already crawled the site and captured the hidden link and is now sending out odd random requests to pages, probably on varying IPs. Almost none of the captured requests report that they ARE bots in any form. I’ve seen Firefox 160, variations on Chrome and Safari but only 1 listed itself as a python crawling library which also suggests crude attempts to not get stopped by UserAgent checking.

I don’t for one moment believe this is stopping that much of anything, but hopefully blocks a few. I’d love there to be a suitable tech stack to allow a human only internet, but sadly that ship sailed long before I was even aware of what the internet was. Perhaps we will need some sort of human to human key validation, like the old PGP key signing days, and even then it would only take a single bot with a single signed key before it all fell apart. And if humans are meeting to secretly validiate that we’re each humans, then we’re back to enforced socialisation in any case.
