title: .htaccess hide .PHP and rewrite URL
body: <p>I've set up a .htaccess file to rewrite the url <code>example.com/foo</code> too <code>example.com/foo.php</code> I can separately get the URL to redirect to <code>error.php</code> if it ends in .php, but I can't seem to do both together.</p>
  
  <p>I've seen other sites hide .php and I want to understand how to do that.</p>
  
  <p>Here's what I've tried:</p>
  
  <pre><code>//.htaccess file
  
  RewriteEngine On    # Turn on the rewriting engine
  RewriteRule    ^([A-Za-z0-9-_]+)/?$    $1.php    [NC,L]
  RewriteRule    ^([A-Za-z0-9-_]+).php?$    error.php    [NC,L]
  </code></pre>
  
  <hr>
  
  <p><strong>NOTES</strong></p>
  
  <p>Here is what worked for me. I'm going to leave it hear for reference as I'm not sure it all necessarily is necessary.</p>
  
  <pre><code>    RewriteEngine On
  
      RewriteRule (.*)index$ http://%{HTTP_HOST}/error [R=404]
      RewriteCond %{THE_REQUEST} ^\w+\ /(.*)\.php(\?.*)?\ HTTP/
      RewriteRule ^ http://%{HTTP_HOST}/error [R=301]
      RewriteCond %{REQUEST_FILENAME}.php -f
      RewriteRule .* $0.php
      ErrorDocument 404 /error.php 
      ErrorDocument 301 /error.php 
  </code></pre>