Using .htaccess file in Apache

2019-02-17 21:24发布

问题:

There is any performance issue using .htaccess with the 'deny from all' instruction in all main directories in an web aplication? Tks.

回答1:

Using .htaccess files slows down Apache. If you can, modify the main server config file (usually called httpd.conf)

From the manual:

You should avoid using .htaccess files completely if you have access to httpd main server config file. Using .htaccess files slows down your Apache http server. Any directive that you can include in a .htaccess file is better set in a Directory block, as it will have the same effect with better performance.

http://httpd.apache.org/docs/current/howto/htaccess.html.

On the other hand if you want to discuss or argue the performance loss versus the loss of ease of maintenance see this post by Simon Greenhill and his benchmarking results.



回答2:

Sorry to revive this. I found an article that explains why .htaccess may slow down your Apache server that's relevant to this question I think.

From the article:

the .htaccess page may slow down your server somewhat; for most servers this will probably be an imperceptible change. This is because of the location of the page: the .htaccess file affects the pages in its directory and all of the directories under it. Each time a page loads, the server scans its directory, and any above it until it reaches the highest directory or an .htaccess file. This process will occur as long as the AllowOverride allows the use of .htaccess files, whether or not the file the .htaccess files actually exists.

This helped me. I hope it helps you all.