title: htaccess to redirect all files to index.php apart from a specific subdirectory
body: <p>I have a site in which all requests should go to index.php, apart from those in a specific subdirectory, which should go to subdirectory/index.php.</p>
  
  <p>I would like the directory path to be translated to a query string for use in the subdirectory index page.</p>
  
  <p>I really have very little idea about htaccess files and I'm sure this question has been answered a hundred times, but I can't work out what to search for to get an answer.</p>
  
  <p>So - this is what I would like to happen under these conditions...</p>
  
  <pre><code>RULE 1
  www.example.com/anything_or_nothing &lt;goes to&gt; /index.php
  www.example.com/anything/anything_else &lt;goes to&gt; /index.php
  RULE 2
  www.example.com/subdirectory/ &lt;goes to&gt; /subdirectory/index.php
  RULE 3
  www.example.com/subdirectory/some_other_directory/ &lt;goes to&gt; /subdirectory/index.php?a=some_other_directory
  </code></pre>
  
  <p>This is what I have currently.  It doesn't work - At least, RULE 1 does work, RULE 2 works (though I think this is only because the physical /subdirectory exists and the index.php is served as a default.) <strong>RULE 3 doesn't work.</strong></p>
  
  <pre><code>Options All -Indexes
  RewriteEngine On
  RewriteBase /
  RewriteCond %{SCRIPT_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  
  RewriteCond %{REQUEST_URI} !^/?timeline/
  #RULE 1
  RewriteRule ^.*$ ./index.php
  #RULE 2
  RewriteRule ^/sub.*$ /sub/index.php
  #RULE 3
  RewriteRule ^/sub/([^/\.]+)/?$ /sub/index.php?a=$1 [L,NC]
  </code></pre>
  
  <p>I have been unable to get a .htaccess file working in the subdirectory, so I'd like the rules all to be in the root .htaccess file.</p>
  
  <p>I have cobbled this .htaccess together from other sites, so I do apologise for my level of ignorance, but I'm just not sure where to go...    </p>
  
  <p>Thank you in advance.</p>
  
  <p>ADDITIONAL INFO>>>>>>>></p>
  
  <p>Other things I have tried.</p>
  
  <p>This</p>
  
  <pre><code>RewriteRule ^/sub/([^/\.]+)/?$ /sub/index.php?a=$1 [L,NC]
  RewriteRule ^/sub.*$ /sub/index.php
  RewriteRule ^.*$ ./index.php
  </code></pre>
  
  <p>Stops all rules from working.</p>
  
  <p>This:</p>
  
  <pre><code>RewriteRule ^.*$ ./index.php
  RewriteRule ^/sub/([^/\.]+)/?$ /sub/index.php?a=$1 [L,NC]
  RewriteRule ^/sub.*$ /sub/index.php
  </code></pre>
  
  <p>Seems to behave as the original example.</p>