.htaccess impact on site speed

I’m a big fan of the 6G firewall, from Jeff Starr of Perishable Press. It lives in my .htaccess file, and does a great job of protecting my site against a wide variety of malicious requests, bad bots, spam referrers, and other attacks. It adds 76 lines to my .htaccess file, some of them filled with long regular expressions. WordPress and Litespeed Cache also add chunks to my .htaccess file. And, .htaccess being exceptionally flexible and useful, I add other stuff as well.

htaccess impact on site speed

My .htaccess file is executed – and the regular expressions are compiled – on every request, so it takes a bit of processing time. I got to wondering – since my .htaccess is kinda long, is it slowing my site speed? My site speed is kinda amazing, but could it be even better with a smaller .htaccess?

The Interwebs provide ample advice on keeping my .htaccess as lean as possible. Frequently the guides recommend moving .htaccess directives into the server configuration file. Great advice, if I had access to the server configuration file – the vast majority of site operators do not. Some Interweb guides warn of “substantial” performance degradation caused by .htaccess, without quantifying what “substantial” means.

So, I decided to test for myself. Not terribly scientific or extensive, but enough to satisfy my curiosity. I used webpagetest.org. Being in Northern California, I chose San Francisco as the test location. I chose the maximum of nine tests per run, and used the median result. I tested with the 6G firewall – and some other firewall stuff that I’ve added – included and not included in .htaccess. I tested with caching active – both LiteSpeed and CloudFlare – and with caching disabled.

The results … With a small .htaccess, with caching disabled, my site is about 3% faster than with a larger .htaccess (speed index of 1.48 vs. 1.53). With caching enabled – the way my site nearly always operates – the difference is cut in half, to 1.5% (speed index of 1.24 vs. 1.26).

My POV … while I am kinda obsessed with squeezing every ounce of speed out of my site, an imperceptible 1.5% difference is not enough for me to give up the excellent protection provided by the 6G firewall, nor the other benefits of .htaccess.

I may revisit this topic when the 7G firewall enters production. Looks like it will be about twice as long as 6G.


WPPOV supports freedom from Net Neutrality and the GDPR. The Internet of the people, by the people, for the people, shall not perish from the Earth.