尽管在前一个上有[L]标志,但仍会评估RewriteRule语句

I've been trying build an if/else branching logic which goes like this:

if ( <URL> corresponds to an existing file ( with the exception of those within the "server" directory ) ) {
    don't modify <URL>
}
else if ( "pages/<URL>.(html|php)" corresponds to an existing file ) {
    re-write it to that
}
else {
    re-write the URL to index.php
}

And here is the .htaccess file I came up with:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !^server/
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ".*" "-" [L]

RewriteCond "pages/%{REQUEST_FILENAME}\.(html|php)" -f
RewriteRule "(.*)" "pages/%1.$1" [L]

RewriteRule ".*" "index.php" [L]

The issue I'm having is this:

When I visit server/lib/router.php, it executes that script, when instead it is supposed to execute index.php.

Now, I understand that the L flag in .htaccess triggers another iteration of the URL-rewriting logic, but I don't get how this results in the last rule being ultimately executed.

-f parameter for RewriteCond expects a filesystem path.

The right syntax is:

RewriteCond %{REQUEST_FILENAME} !^server/
RewriteCond /path/to/your/server/root/%{REQUEST_FILENAME} -f
RewriteRule ".*" "-" [L]

You may have to edit the same directive on the second rule too.