title: Rewrite php file to a folder instead of using a folder called /about
body: <p>My url right now is:</p>
  
  <pre><code>localhost/about/index.php
  </code></pre>
  
  <p>Result wanted:
  <code>localhost/about.php</code> But I want it to appear as <code>localhost/about/</code> without having to place it into an about folder.</p>
  
  <p>I'm quite inexperienced on how you would do this with a <code>.htaccess</code> file.</p>
  
  <h2>I found this idea online, but mine isn't using a database:</h2>
  
  <p>Example 3: The site has an unwieldy URL. How to clean it up
  This sort of situation can arise when URLs are long and complex.</p>
  
  <p>Take the URL below as an example:</p>
  
  <pre><code>http://example.com/results.php?products=produce&amp;type=fruit&amp;species=apple
  </code></pre>
  
  <p>As effective as the URL is in delivering the correct content, it is not very memorable for the consumer. URL rewrites would allow you to convert the URL to something simpler and clearer:</p>
  
  <pre><code>http://example.com/produce/fruit/apple
  </code></pre>
  
  <p>In order to accomplish this, we would need the following lines in our <code>.htaccess</code> file (you can add as many section as needed in the <code>.htaccess</code> file):</p>
  
  <pre><code>RewriteEngine on
  RewriteRule ^(meat|produce|dairy)/([^/.]+)/([^/.]+)$ results.php?products=$1&amp;type=$2&amp;species=$3
  </code></pre>
  
  <p>Now for an explanation: </p>
  
  <p>First the <code>^(caret)</code> starts the expression.</p>
  
  <p><code>(meat|produce|dairy)</code>: If we want to limit the options that can be typed in, we can specify the only values we will accept: in this case the variety of groceries. If anything besides one of those three 3 keywords is typed in, the URL rewrite will not take place.</p>
  
  <p>The <code>([^/.]+)</code> indicates that anything can be written between the forward slash besides the characters following the caret, in this case, the forward slash or period.</p>
  
  <p><code>results.php?products=$1&amp;type=$2&amp;species=$3</code>: Each value in the parentheses will be extracted and then applied to the longer URL in the substitution part of the expression. <code>$1</code> indicates the first parantheses, <code>$2</code>, the second, <code>$3</code>, the third.</p>