Apache rewrite outside DocumentRoot

Usually if we want to handle a not found error we have to use a roule like this:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* /notfound.php [L]

Today I’ve met an interesting case. The VirtualHost was setup only for provide media and the error handler script was outside the DocumentRoot.

Devs tried this conf, but of course, didn’t work.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* ../notfound.php [L]

The correct conf is use an Alias in VirtualHost configuration and keep the original rewrite roule in htaccess.

Alias /notfound.php /var/www/site/htdocs/notfound.php

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* /notfound.php [L]