title: Serve HTML file if it exists, otherwise redirect to index with mod_rewrite
body: <p>I'd like to write a rewrite rule to do the following: if any of the following files exist on the server as a static html file in a specific directory then I'd like <code>.htaccess</code> to serve that static file. Otherwise, I'd like the <strong>id</strong> (first number after the slash) to be passed as a query parameter to <code>www.gallery.com/index.php</code></p>
  
  <pre><code>www.gallery.com/1-driving-to-the-beach.html   
  www.gallery.com/2-swimming.html
  </code></pre>
  
  <p>Example: assume <code>www.gallery.com/2-swimming.html</code> doesn't exist as an html file on the server. I want <strong>id=2</strong> to be sent to <code>/index.php</code> where I can use</p>
  
  <pre><code>&lt;?php
  ob_start();
  ?&gt;
  &lt;html&gt;&lt;/html&gt;
  &lt;?php
  file_put_contents('2-swimming.html', ob_get_contents());
  ?&gt;
  </code></pre>
  
  <p>Questions:</p>
  
  <ol>
  <li>What is the rewrite rule my <code>.htaccess</code> file should contain?</li>
  <li>How do I grab the <strong>id</strong> in <code>index.php</code> when the url is redirected by .htaccess?</li>
  </ol>