Forum Moderators: phranque
I have a website where I am doing a lot of mod_rewriting. As such it works fine (just about every single page request is a .html url being rewritten to a php script that draws from mysql). The server is an almost dedicated box (I have a few low traffic sites there as well), Pentium III 733 and it has atleast 30,000 daily pageviews (probably 50,000). Everything runs well, very quick response times.
Now my question is, where I should do my mod_rewriting for best performance. At this time I have 8+ directories that contain a .htaccess that does the mod_rewrites for the directory; ie. in directory x: I might redirect ^[a-z]+.html$ to /scripts/page.php?section=x&p=$1. I am wondering though.. Should I instead delete all those directories and do it all via a number of rewrite rules in a single .htaccess at public_html/? ie. for directory x ^x/[a-z]+.html$ to /scripts/page.php?section=x&p=$1 etc. In short it is: ONE big .htaccess (more rules to check with each hit) for all rewrites/error page definitions etc. rather than one in each directory(less rules to check)?
Welcome to WebmasterWorld [webmasterworld.com]!
The most efficient approach will be to try to achieve the following:
Of course, this is much easier to do with a new site design, when you can plan ahead.
Additionally, those RewriteRules which apply to most files and which are not likely to change can be placed in httpd.conf if you have access to the server configuration. Directives placed in httpd.conf are compiled on server restart, rather than being interpreted on a per-request basis. Therefore, they are processed much more efficiently.
Jim
Yes, you can, IF you have access (priveleges) to modify httpd.conf, and IF the "design" of your code is stable and not likely to change. However, the great majority of Webmasters do not have access to httpd.conf, thus leading to the popularity of .htaccess.
The original post mentioned only .htaccess, so the thrust of my reply was to .htaccess, but I did mention httpd.conf as a final note in my first reply.
Do you have a question about what is posted here, or are you just commenting on the use of httpd.conf?
Jim