Hey all. I was just wondering if there's a limit for the .htaccess file for Apache 2. I'm working on a caching plugin and thaught that it might be a good idea to use the .htaccess file to point to generated static html files.

So, anybody ever tried to reach the limit? Will .htaccess work fine with 5,000 mod_rewrite rules? What about 10,000? 20,000? A friend of mine said he worked on a blog which had 400k+ posts. Will that ever work?


~ @kovshenin


I'm pretty sure there's no hard limit on how many mod_rewrite rules you can use; apache will basically see the .htaccess file and run through the mod_rewrite rules in order

However, there's a few limits you might run into:

  1. File size. There might be a limit of 2GB or 4GB on the size of the .htaccess file. There might be a lower effective limit based on memory (the .htaccess file may get read into memory)
  2. Time. Each mod_rewrite takes some time to process (even if it doesn't match), eventually you'll get enough that you can measure the time in seconds, which would be very bad.

You may want to explore the RewriteMap directive and set up a hash file and reduce your 20,000 mod_rewrite rules to a single rule that looks up an entry in a 20,000 item hash file database instead.

| improve this answer | |
  • +1 for good explanation and special considerations. – Urda Feb 17 '10 at 18:54

If you're the server admin you should not use .htaccess as recommended by Apache. Everything in an .htaccess file can and should be in a <Directory> block in the config. Reason being, Apache will hit the hard drive on every single request to read and parse this file before serving the content. It's an extraordinary performance hit.

So, would you put 20,000 lines in your config for it to be loaded by memory? You're best off storing the rules in a database.

Recommended reading: http://httpd.apache.org/docs/2.0/howto/htaccess.html

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.