Popular Post
Blog Syndications
Portfolio
Projects Connaxis
CakePHP: Using mod_rewrite without .htaccess overhead
Added by:19 July 2009 16:59
A quick solution for all of you who want to disable .htaccess files on their server but still use mod_rewrite with CakePHP:
<Directory /var/www/mysite>
AllowOverride None
Options FollowSymLinks
RewriteEngine on
RewriteRule ^$ /app/webroot/ [L]
RewriteCond %{REQUEST_URI} !^/app/webroot.*
RewriteRule ^(.*)$ /app/webroot/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^app/webroot(.*)$ /app/webroot/index.php?url=$1 [QSA,L]
</Directory>
If .htaccess files are enabled (e.g. AllowOverride All) apache needs to check the directory path for ".htaccess" files on EVERY request. This means a significant overhead for high-traffic sites as traversing the directory path and opening the ".htaccess" files are not for free. The above code can easily be put in a apache virtual host configuration to prevent the .htaccess overhead and still have nice SEO-friendly Cake URLs.
more4 Comments
Add Comment
mai
Posts: 4
Posts: 4
Reply #4 on : Thu August 06, 2009, 15:58:04
mai
Posts: 4
Posts: 4
Reply #3 on : Thu August 06, 2009, 08:19:22
Abba Bryant
Posts: 4
Posts: 4
Reply #2 on : Fri July 31, 2009, 20:38:00
jamesF
Posts: 4
Posts: 4
Reply #1 on : Thu July 30, 2009, 05:37:45

