(on Thursday, 06 November 2008, 05:09 AM -0800):
> The documentation recommends:
>
> RewriteEngine On
> RewriteCond %{REQUEST_FILENAME} -s [OR]
> RewriteCond %{REQUEST_FILENAME} -l [OR]
> RewriteCond %{REQUEST_FILENAME} -d
> RewriteRule ^.*$ - [NC,L]
> RewriteRule ^.*$ index.php [NC,L]
>
> ... but wouldn't this be simpler?
>
> RewriteEngine On
> RewriteCond %{REQUEST_FILENAME} !-f
> RewriteCond %{REQUEST_FILENAME} !-d
> RewriteCond %{REQUEST_FILENAME} !-s
> RewriteRule .* index.php
They're not equivalent.
The one in the docs says that if the filename is a file with size, or a
symlink, or a directory, serve it as is; otherwise, rewrite to index.php
The one you recommend says that if the filename is _not_ a file, _not_ a
directory, and does _not_ have size, rewrite it to index.php.
There are several differences.
* The recommended version takes account of symlinks. This is
particularly important when you're versioning CSS or JS libs, as you
will often use a symlink to point to the most current version, while
keeping the original. One trick I use with Dojo, for instance, is to
symlink to my Dojo source directory during development, and then
switch that symlink to my Dojo build directory during deployment;
this eliminates the need to change any actual code or use a
configuration value for my dojo path.
* The recommended version makes it possible to easily insert rules
between the two rewrite rules -- so that if the file does not exist,
you can rewrite to another location prior to rewriting to index.php.
(You can accomplish this in your rule by preceding the rule with
additional rules.)
* I personally prefer asserting positives, not negatives. It's simpler
to understand. But that's a personal preference.
Yes, you can certainly use the rule you specify (though I'd change the
first line to "!-l"). I don't think we'll likely change our
recommendation, however.
--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/
没有评论:
发表评论