The check against -f
fails because of the trailing slash so you need to do an additional check against it without a possible trailing slash:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.*?)/?$
RewriteCond %{DOCUMENT_ROOT}/%1.php -f
RewriteRule ^(.*?)/?$ $1.php
</IfModule>
how rewrite conditions and rewrite rules work. Does it follow if any of these conditions match then do this. And what about the -d and -f, what are they doing?
Any number of conditions preceding a rule only apply to that rule and they are all required to match. If you want one condition or another, then you can include the [OR]
flag at the end of the condition:
RewriteCond %{REQUEST_FILENAME} !-d [OR]
RewriteCond %{REQUEST_FILENAME} !-f
As for the -f
and -d
, they are resource checks, to see if a given path points to a file or a directory. See apache's mod_rewrite docs for the full explanation.