Links
Previous Posts
- Howto: Setup a Mac Mini as a BGP Router
- We are getting quicker
- Can I please have some money for my idea?
- A House Price Crash could be very close
- The Birth of our Talkon.it Network
- Livetodot is getting much better
- Fubra breaks the 3 million UV barrier!
- Installing our new Rackable racks
- The London 2012 logo saga
- First Mac Mini BGP routers on world's largest Internet exchange
Archives
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- October 2007
- September 2007
- August 2007
- June 2007
- April 2007
- March 2007
- February 2007
- November 2006
- August 2006
- June 2006
- March 2006
- February 2006
- January 2006
- December 2005
- November 2005
- October 2005
- September 2005
- August 2005
- July 2005
- June 2005
- May 2005
- April 2005

.htaccess vs httpd.conf
Posted 1:19 AM Monday January 7, 2008 by Dawid Golunski
If you are an Apache user you will have certainly heard about the two different ways to make configuration changes to Apache server. The first one is to make changes directly inside the main configuration file (i.e httpd.conf) and the second is to use .htaccess files. The second method allows us to make configuration changes on a per-directory basis.
There are some general opinions that tell you to never use .htaccess files on your web server, putting all the options in the main configuration file.
Here is a quote from Apache documentation:
Setting up a test environment
First of all we need to edit our Apache httpd.conf file in order to set up two separate directories and enable .htaccess files for one of them:
Now we need to create the directories:
and .htaccess file:
We also need to create simple pages so we could request them later:
After restarting the server:
Testing
By using the following command we can see how long it will take to request each of the pages 500 times:
Repeating the test 5 times for each of the URL's we achieve the following results:
That gives us a difference of around 6.6% less requests per second while .htaccess is turned on.
There are some general opinions that tell you to never use .htaccess files on your web server, putting all the options in the main configuration file.
Here is a quote from Apache documentation:
When AllowOverride is set to allow the use of .htaccess files, Apache will look in every directory for .htaccess files. Thus, permitting .htaccess files causes a performance hit, whether or not you actually even use them! Also, the .htaccess file is loaded every time a document is requested.which sounds pretty scary! Since .htaccess files offer many advantages including much greater flexibility (possibility of making changes on the fly without root access, and without a need to restart the server), we decided not to give up on using them that easily and to carry out some tests ourselves to see the actual impact they have on performance.
Setting up a test environment
First of all we need to edit our Apache httpd.conf file in order to set up two separate directories and enable .htaccess files for one of them:
<Directory /var/www/html/htaccess-enabled>
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/html/htaccess-disabled>
AddHandler php5-script .php_script
Options FollowSymLinks
AllowOverride None
</Directory>
Now we need to create the directories:
# mkdir /var/www/html/htaccess-enabled # mkdir /var/www/html/htaccess-disabled
and .htaccess file:
# echo 'AddHandler php5-script .php_script' \ >/var/www/html/htaccess-enabled/.htaccess
We also need to create simple pages so we could request them later:
# echo '.htaccess enabled' \ >/var/www/html/htaccess-enabled/enabled.html # echo '.htaccess disabled' \ >/var/www/html/htaccess-disabled/disabled.html
After restarting the server:
# apachectl restartwe can start our tests.
Testing
By using the following command we can see how long it will take to request each of the pages 500 times:
# time for i in `seq 5000`; do \ curl http://localhost/htaccess-disabled/disabled.html >/dev/null;done real 0m51.677s user 0m28.482s sys 0m21.101s # time for i in `seq 5000`; do \ curl http://localhost/htaccess-enabled/enabled.html >/dev/null;done real 0m52.217s user 0m28.206s sys 0m21.317sIn order to get more comprehensive results we can use ab (Apache Benchmark) program as follows:
# ab -n 5000 -c10 http://localhost/htaccess-disabled/disabled.html # ab -n 5000 -c10 http://localhost/htaccess-enabled/enabled.html-n denotes number of requests, and -c number of requests to be sent at the same time.
Repeating the test 5 times for each of the URL's we achieve the following results:
| .htaccess disabled: | ||
| Time (s) | Requests per second | |
| 1.10 | 4539 | |
| 1.13 | 4429 | |
| 1.12 | 4451 | |
| 1.13 | 4424 | |
| 1.67 | 4683 | |
| Average | 1.23 | 4505 |
| .htaccess enabled: | ||
| Time (s) | Requests per second | |
| 1.85 | 4606 | |
| 1.21 | 4121 | |
| 1.19 | 4188 | |
| 1.22 | 4098 | |
| 1.24 | 4026 | |
| Average | 1.34 | 4208 |
That gives us a difference of around 6.6% less requests per second while .htaccess is turned on.