You're goinmg to need to return the 404 through a php script:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /404.php?path=$1 [L]
And in the 404.php file
:
<?php
header("HTTP/1.0 404 Not Found");
print('The file that you requested: ' . $_GET['path'] . ' was not found\n');
// or include a special 404 page
include ('/path/to/' . $_GET['path']);
?>
Or you could lose the ?path=$1
part completely and just look in $_SERVER['REQUEST_URI']
.