A CakePHP Apache Optimization Tip

Friday, November 23rd

This post on the CakePHP google group caught my eye today and my nerd tendencies emerged from their Thanksgiving day too much food and beer hangover.

I will preface this by saying that

  1. I know enough about Apache web server to get by. I'm no expert.
  2. I have not tested this in a production environment.

This optimization tip involves moving the rewrite directives in app/webroot/.htaccess into the apache httpd.conf file.

The default CakePHP .htaccess file looks like this:

<IfModule mod_rewrite.c>
	RewriteEngine On
	RewriteCond %{REQUEST_FILENAME} !-d
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

Here's what I did to move these directives into my /etc/apache2/httpd.conf file. I have my development server setup to use multiple virtual hosts for each of my projects. So for this website, here is what my vhost entry looks like:

<VirtualHost *:80>
	DocumentRoot /www/jc/webroot
	ServerName jc.dev
<Directory /www/jc/webroot>
	AllowOverride None
<IfModule mod_rewrite.c>
		RewriteEngine On
		RewriteCond %{REQUEST_FILENAME} !-d
		RewriteCond %{REQUEST_FILENAME} !-f
		RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
</Directory>
</VirtualHost>
The key to this is that your DocumentRoot direcitve is set to the webroot dir.
Add a Comment