This question is somewhat related to my previous question. The trick of using $_SERVER[\'REDIRECT_QUERY_STRING\'] seems to work only for $_GET var
$_SERVER[\'REDIRECT_QUERY_STRING\']
$_GET
Use the FallbackResource directive instead of the ErrorDocument directive of Apache: it does the trick FallbackResource on Apache website
FallbackResource
ErrorDocument
Example:
FallbackResource /404.php