2008年11月6日星期四

[fw-mvc] Re: Re[fw-mvc] commended mod_rewrite rule

* My version also includes symlinks (-s should be -l, my apologies).

* As you say, this can also be done with my version.

* True, but which sounds better:

- If s/l/d, do nothing, else rewrite to index.php (*)
- If not s/l/d, rewrite to index.php

(*) Also, the first RewriteRule only serves to 'exit' rewriting, and has no
other purpose.

It's kinda like writing:

if (bool) {
// ...
} else {
go();
}

... instead of:

if (!bool) {
go()
}

AFAIK, since you are matching 'anything' (.*), the anchors (^ and $) are
unnecessary, and so is the NC (no case) flag.

Regards,

Glen.


Matthew Weier O'Phinney-3 wrote:
>
> -- Dodger <glen.84@gmail.com> wrote
> (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/
>
>

--
View this message in context: http://www.nabble.com/Recommended-mod_rewrite-rule-tp20360712p20362811.html
Sent from the Zend MVC mailing list archive at Nabble.com.

没有评论: