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.