title: apache mod_rewrite one rule for any number of possibilities
body: <p>I'm building a fairly large website and my .htaccess is starting to feel a bit bloated, is there a way of replacing my current system of - one rule for each of the possibile number of vars that could be passed, to one catch all expression that can account for varying numbers of inputs ?</p>
  
  <p>for example I currently have:</p>
  
  <pre><code>RewriteRule ^([a-z]+)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)$ /index.php?mode=$1&amp;id=$2&amp;$3=$4&amp;$5=$6
  RewriteRule ^([a-z]+)/([^/]*)/([^/]*)/([^/]*)$ /index.php?mode=$1&amp;id=$2&amp;$3=$4
  RewriteRule ^([a-z]+)/([^/]*)$ /index.php?mode=$1&amp;id=$2
  RewriteRule ^([a-z]+)$ /index.php?mode=$1
  </code></pre>
  
  <p>the first backreference is always the <em>mode</em> and (if any more exist) the second is always <em>id</em>,  thereafter any further backreferences alternate between the name of the input and its value</p>
  
  <pre><code>http://www.example.com/search
  http://www.example.com/search/3039/sort_by/name_asc/page/23
  </code></pre>
  
  <p>I would love to be able to have one expression to gracefully handle all the inputs.</p>