title: How can I redirect all sub-directories to root using htaccess or httpd.conf?
body: <p>I have an index file that builds content based on <em>n</em> PATH_INFO variables.</p>
  
  <p>Example:</p>
  
  <pre><code>site.com/A/B/n/
  </code></pre>
  
  <p>should use index.php at either:</p>
  
  <pre><code>site.com/index.php?var1=A&amp;var2=B&amp;varN=n
   - or - 
  site.com/index.php/A/B/n/
  </code></pre>
  
  <p>instead of:</p>
  
  <pre><code>site.com/A/B/n/index.php || which doesn't exist ||
  </code></pre>
  
  <p>So far I've tried a number of variations of:</p>
  
  <pre><code>RedirectMatch ^/.+/.*$ /
  </code></pre>
  
  <p>with no success.</p>
  
  <p>I have an inelegant and unscalable solution here:</p>
  
  <pre><code>RewriteEngine On 
  RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?p1=$1 [NC,L]
  RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ index.php?p1=$1&amp;p2=$2 [NC,L]
  RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ index.php?p1=$1&amp;p2=$2&amp;p3=$3 [NC,L]
  RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ index.php?p1=$1&amp;p2=$2&amp;p3=$3&amp;p4=$4 [NC,L]
  </code></pre>
  
  <p><strong>Problems with this solution:</strong></p>
  
  <ul>
  <li>Inelegant and unscalable, requires manual line for each subdirectory</li>
  <li>Fails with non alphanumeric characters (primarily +,= and &amp;) ex. site.com/ab&amp;c/de+f/
  (note, even changing the regex to ^([a-zA-Z0-9_-<strong>\+\=\&amp;</strong>]+)/?$ does little to help and actually makes it error out entirely)</li>
  </ul>
  
  <p>Can you help?</p>