title: htaccess recursive mod_rewrite
body: <p>I like to use mod_rewrite to essentialy rewrite a path that doesn't actually exist creating a virtual structure.  The problem that has been nagging me, is suppose I want to redirect  /articles/  , I find I must create a seperate rule for each sub folder and additionaly, in order to handle the paths with or without the / at the end, requires yet another rule, so 2 x the rules for every path or sub path I need to write a controller for.  An example is as follows of what I have been doing :</p>
  
  <pre><code>RewriteRule ^articles/$ /articles.php [NC,L,QSA]
  RewriteRule ^articles$ /articles.php [NC,L,QSA]
  </code></pre>
  
  <p>Additionally, I end up having to do stuff like this</p>
  
  <pre><code>RewriteRule ^articles/(.*)/$ /articles.php [NC,L,QSA]
  RewriteRule ^articles/(.*)/(.*)/$ /articles.php [NC,L,QSA]
  RewriteRule ^articles/(.*)/(.*)/(.*)/$ /articles.php [NC,L,QSA]
  RewriteRule ^articles/(.*)/(.*)/(.*)/(.*)/$ /articles.php [NC,L,QSA]
  RewriteRule ^articles/(.*)/(.*)/(.*)/(.*)/(.*)/$ /articles.php [NC,L,QSA]
  
  RewriteRule ^pages/(.*)/$ /pages.php [NC,L,QSA]
  RewriteRule ^pages/(.*)/(.*)/$ /pages.php [NC,L,QSA]
  RewriteRule ^pages/(.*)/(.*)/(.*)/$ /pages.php [NC,L,QSA]
  RewriteRule ^pages/(.*)/(.*)/(.*)/(.*)/$ /pages.php [NC,L,QSA]
  RewriteRule ^pages/(.*)/(.*)/(.*)/(.*)/(.*)/$ /pages.php [NC,L,QSA]
  </code></pre>
  
  <p>I may be stretching here, but this seems to be terribly inefficient, and logically, there must be a simple way to be able to handle the control of an entire sub folder and all of it's sub contents.</p>
  
  <p>My question is this >>>  How can I simplify this into one line for each path that I wish to handle ?</p>