mod_rewrite REQUEST_FILENAME doesn't contain absolute path

Solution 1:

Took me a while to find out as well, but the reason is mentioned in the mod_rewrite documentation:

REQUEST_FILENAME The full local filesystem path to the file or script matching the request, if this has already been determined by the server at the time REQUEST_FILENAME is referenced. Otherwise, such as when used in virtual host context, the same value as REQUEST_URI.

That's why it works in .htaccess but not in the conf file of the vhost. (And that's also why adding the DOCUMENT_ROOT works around the problem).

Solution 2:

I resolved this by explicitly writing the document root into the condition

RewriteCond /path/to/my/public_html%{REQUEST_FILENAME} !-f
RewriteCond /path/to/my/public_html%{REQUEST_FILENAME} !-d