title: Adding mod-rewrite to an existing PHP website
body: <p>I am updating a php app, which currently does not use url rewriting. The aim is to hide file extensions. The general structure of the website is as follows</p>
  
  <pre><code>root/
    index.php
    login.php
    page1.php
    page2.php
    page3.php
    page4.php
    page5.php
    page6.php
    page7.php
    page8.php
  subfolder/
    index.php
    validpage.php
  images/
  css/
  </code></pre>
  
  <p>The subfolder folder in the above structure is unique in that it is the only subfolder containing php files.All of the other files are in the root folder.</p>
  
  <p>I have been through these questions <a href="https://stackoverflow.com/questions/788188/mod-rewrite-and-php">Mod Rewrite and PHP</a> and <a href="https://stackoverflow.com/questions/1868154/mod-rewrite-or-php-router">Mod-Rewrite or PHP router?</a> and <a href="https://stackoverflow.com/questions/265898/mod-rewrite-php-and-the-htaccess-file">mod_rewrite, php and the .htaccess file</a> </p>
  
  <p><strong>Updated</strong> htaccess. thanks to <a href="https://stackoverflow.com/users/438024/thomasmalt">@thomasmalt</a></p>
  
  <pre><code>RewriteEngine on
  RewriteBase /
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d [OR]
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -l 
  RewriteRule ^.*$ - [NC,L]
  
  
  # only rewrite if the requested file doesn't exist
  RewriteCond %{REQUEST_FILENAME} !-s 
  
  # add .php to the url     
  RewriteRule ^(.*)$ $1.php
  </code></pre>
  
  <p>Problem now is I get a 500 instead of a 404 error, when I try to access a non existent page like localhost/inex.php. The <strong>Apache error log</strong> gives me the following errors. (I accessed localhost/index which loaded the contents of index.php , followed by which I loaded localhost/inex which gave me a 500 error.)</p>
  
  <pre><code>[Sat Sep 25 14:44:26 2010] [error] [client 127.0.0.1] File does not exist: C:/wamp/www/index
  [Sat Sep 25 14:44:36 2010] [error] [client 127.0.0.1] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
  </code></pre>
  
  <p><strong>Update</strong>: found the answer to my question <a href="https://stackoverflow.com/questions/1745680/htaccess-rewrite-causes-500-error-instead-of-404/1750696#1750696">here</a>. The question is resolved.</p>