title: Mod_rewrite check if php file exists
body: <p>I'm trying to write a few mod_rewrite rules. Everything is working fine at the moment. At the moment my generic URLs look like this:</p>
  
  <pre><code>http://website.com/about-us
  http://website.com/privacy
  </code></pre>
  
  <p>At the moment, these 2 links are mod_rewritten to <code>content.php</code>, because <code>about-us</code> and <code>privacy</code> don't exist as .php files, but rather, their content is stored in a database, which content.php retrieves.</p>
  
  <p>I have another url:</p>
  
  <pre><code>http://website.com/contact-us
  </code></pre>
  
  <p>Which does exist as a .php file, because it contains custom data.
  How can I check to see if <code>contact-us.php</code> exists. If it does, redirect <code>website.com/contact-us</code> to <code>website.com/contact-us.php</code>, otherwise, redirect to <code>website.com/content.php</code></p>
  
  <p>Below is my mod_rewrite file as it stands:</p>
  
  <pre><code>RewriteEngine On
  
  # I want the following condition and rule to look to see if the .php file exists,
  # and if it does, redirect to the physical page, otherwise, redirect to content.php
  RewriteCond %{DOCUMENT_ROOT}/([a-zA-Z0-9\-_]+).php -f
  RewriteRule ^([a-zA-Z0-9\-_]+)\.php$ [L]
  
  
  RewriteRule ^([a-zA-Z0-9\-_]+)$ /content.php [L]
  RewriteRule ^(product1|product2|product3)/(designer1|designer2|designer3)$ /search.php?productType=$1&amp;designer=$2 [L]
  RewriteRule ^sale/(product1|product2|product3)$ /search.php?sale=1&amp;productType=$1 [L]
  </code></pre>
  
  <p>If you need any further information, please let me know!
  I appreciate the replies :)</p>