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.

2 Responses to “Zend Framework, Rewrite Rules, Apache”

  1. Apache mod_rewrite in Zend and Flex integration- my friend .htaccess | diamondTearz Says:

    […] 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.

  2. Apache mod_rewrite preferred setting- right from ZF Quickstart | diamondTearz Says:

    […] close to the recommended version that I discussed in a previous entry about mod_rewrite and […]

Leave a Reply

You must be logged in to post a comment.