Zend Framework, Rewrite Rules, Apache
Most of the Zend Framework documentation I’ve read recommends a rewrite rule that looks something like this:
RewriteEngine on
RewriteRule !\.(swf|js|ico|gif|jpg|png|css)$ index.php
Why not use a more elegant rule that looks like this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php
This rule basically says: If it’s not an existing file, and it’s not an existing directory - pass the request through index.php.
This allows you far more flexibility when you want to host non-framework files, or a whole slew of other media types that are not listed in your apache configuration.
October 21st, 2008 at 12:00 pm
[…] An elegant approach suggested by Darryl Clark involved writing the rule to redirect if the path is not an existing file or directory then route it to index.php.
October 28th, 2008 at 10:37 am
[…] close to the recommended version that I discussed in a previous entry about mod_rewrite and […]