Cybersecurity

When Not to Use .htaccess: A DDoS Lesson From the Field

In 2011, as the website administrator for one of my clients, I ran into a problem I had not dealt with before: a flood of malicious IP addresses hitting the site in what was clearly a denial-of-service attack. The fix I built at the time was, in hindsight, both clever and a mistake — a 10MB .htaccess file designed to block every offending address at the server level.

It worked, in the narrow sense that it blocked the attackers. It also nearly broke the site for everyone else. A .htaccess file that large, replicated across every sub-directory rather than sitting once at the root, creates serious I/O overhead — the server has to parse that entire file on every single request. The site slowed to a crawl. I had built a moat so large it slowed down the villagers along with the invaders.

What I learned about .htaccess

Used well, .htaccess is a legitimate and useful configuration tool. Used as a growing blocklist, it becomes a liability — a known failure pattern that shows up repeatedly in server administration discussions, and one that is easy to fall into under the pressure of an active attack. When you do not control the underlying host's file system directly, you also lose most of the levers you would normally pull to optimize around the problem.

The better fix: stop blocking at the application layer

The real solution was to stop trying to solve a network-layer problem inside the website's own configuration file, and instead put something in front of the site that was built for exactly this. Cloudflare — free at the entry tier, and effective as both a spam and DDoS filter and a content delivery network — replaced the entire mess. Malicious traffic gets filtered before it ever reaches the origin server; legitimate visitors get a faster site because of the CDN layer on top.

The lesson that stuck

Good intentions do not guarantee a good fix. The instinct to defend the site was right; the implementation solved the immediate problem while quietly creating a worse one. If you are not sure whether your current setup would hold up under the same kind of attack — or whether Cloudflare or something like it is the right fit for your site — that is exactly the kind of question worth a real conversation rather than a guess.

← Back to all articles