title: htaccess: act as if files were in another directory, but RewriteRules seem to be mutually exclusive
body: <p>For files in several subdirectories of <code>/data/</code>, I would like to treat them (and the files inside them) as if they were in the root directory.</p>
  
  <p>So,</p>
  
  <p><strong>1) a request to</strong></p>
  
  <pre><code>/data/foobar/file.png
  </code></pre>
  
  <p>should redirect the browser to</p>
  
  <pre><code>/foobar/file.png
  </code></pre>
  
  <p><strong>2) any requests to</strong></p>
  
  <pre><code>/foobar/file.png
  </code></pre>
  
  <p>should respectively deliver the file <code>/data/foobar/file.png</code>, but without redirection.
  <hr>
  For <strong>1)</strong> I got the following rule working
  :</p>
  
  <pre><code>RewriteCond %{REQUEST_URI} ^(.*)?data/((foobar|and|some|other|subdirs)/.*)$
  RewriteRule .* %1%2 [R=301,L,qsappend]
  </code></pre>
  
  <p><em>(I took this approach usind a <code>RewriteCond</code> with <code>%x</code> references in order to be subdirectory-agnostic, as in my dev environment the page is located in a subdirectory as opposed to the live system where it's in the root of the domain.)</em></p>
  
  <p>And for <strong>2)</strong> the following rule does the trick:</p>
  
  <pre><code>RewriteRule ^((foobar|and|some|other|subdirs)/.*)$ data/$1 [L,qsappend]
  </code></pre>
  
  <p>However, these rules only work if I enable one at a time. If I enable both of them at the same time, the browser will abort the request with a "too many redirects" error. The redirect from <code>/data/*</code> to <code>/*</code> will work, but then end in the aborted request just the same as calling the URL without <code>/data/*</code>.</p>
  
  <p>I'm having a hard time understanding why this is happening. It would be totally logical if both rules actually triggered a redirect. But as far as my understanding of htacccess goes (and the Network tab of the dev console seems to confirm that conception), the client shouldn't even know for case 2) that the file is not actually there. So why does this apparently still count towards the redirection limit?</p>
  
  <p>Is there something fundamental I'm missing? And how can I achieve what I'm trying to achieve?</p>