Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

Thanks,

~ @kovshenin

share|improve this question

2 Answers 2

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

share|improve this answer

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.

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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