I've recently added this little bit of code to my .htaccess
file:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA]
Ok, I understand what's happening here, I think. This little bit of code to remove PHP file extensions causes a loop if the document is not found. This loop causes a 500 server error instead of the (proper) 404. Unfortunately I have very little understanding of what these rewrites are actually doing, so I don't know how to rewrite it to only trigger this redirect if the document exists.
I've done some reading and I'm not sure what Apache considers a "regular" file. I mean it works, but why wouldn't the first line be -f
instead of !-f
? Is -u
the only way to accomplish this?