I used .htaccess to redirect all unknown web pages to a php file which then displayed the correct content based on the page requested. This allowed me to have virtual directories. domain.com/contact etc. The php file then pulled the correct content from the database based on the directory name.
I used ErrorDocument 404 /file.php
However this stops them being indexed by search engines as 404 is ignored…
Well, as an error handler, you’ve got the correct code. In fact, your method is the same (albeit, with different code) as WordPress (which uses mod_rewrite to test for the existence of a file or directory then redirects EVERYTHING to its own index.php script).
As for two different ways of doing the same thing, I use extensionless URIs on my own website and use mod_rewrite to add the .php extension. On one client’s website, I use the article title and redirect to the script to fetch the article based on the URI (or back to the Home Page if not found).
There are lots of ways to do this and, technically, yours is correct. The only problem with using ErrorDocument is that you’re sending a 404 response (not a good thing) with every redirect to your file.php.