I want to test if file exists for both the rules at the bottom, but it only seems to work for the first one. The second rule would wrongly match my /style.css file and display the php page instead of style.css.
Isn’t it supposed to test if file exists for all next rules until the [L]
flag ?
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ browse_folder.php?username=$1&folder=$2
RewriteRule ^([^/]+)/?$ browse_user.php?username=$1 [L]
If I repeat the file_exists test before each of the two lines it works as expected.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ browse_folder.php?username=$1&folder=$2
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ browse_user.php?username=$1 [L]
2
Answers
No, it’s not.
RewriteCond
‘s are applied to the very first-nextRewriteRule
only. From the official documentation:Note the
can precede
aRewriteRule
Workaround
If you don’t want to repeat yourself, you can proceed as following:
RewriteCond
is only applicable to nextRewriteRule
. You can make a separate rule to skip all files and directories on top of other rewrite rules.