title: Mod_rewrite to 404 page if match not found
body: <p>Hey I'm trying to do a mod-rewrite for search engine friendly URLs that resolve to a 404 page if the file isn't found. When I get it working for directories that don't resolve to a file (ie search/.php) because no match is found then it doesn't work when a match is found.</p>
  
  <p>Basically I need it to work when you go to url/search/ if there is an index page and url/search/filename should resolve to filename.php inside of the search directory. Anyone know how to accomplish this? </p>
  
  <pre><code>RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule .? - [S2] #file not found, skip to 404
  RewriteRule ^([^\.]+)$ $1.php [NC,L]
  RewriteRule .? - [S1] #file found, ignore redirect to 404
  RewriteRule (.*) 404.php?file=$1
  </code></pre>