08 July 2011

CakePHP : Changing .htaccess to prevent one (or more) directory from being handled by Cake

This technique may be useful if for example you have decided to use Wordpress to handle your blog, rather than trying to code your own competing blog system.

This .htaccess file is based on the CakePHP default but simply adds a rewrite rule to exclude the "blog" directory from Cake's control.

<ifmodule mod_rewrite.c=""%gt;
   RewriteEngine on
   RewriteRule   ^(blog).* - [NC,L]
   RewriteRule    ^blog /blog    [L]
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]

If you want to prevent Cake from controlling multiple directories you can simply modify the rewrite rule like such:

RewriteRule   ^(blog|my|other|directories|go|here).* - [NC,L]

In order to accomplish this on an IIS server you can email sballmer@microsoft.com and ask for support in getting his expensive software to do what it says it does on the box.