title: Using .htaccess rewrite rules to reflect a "fake" directory structure in the addres bar
body: <p>I'm working with an online encyclopedia and I am trying to achieve the following:
  Given the physical location of a file in <a href="http://example.com/articles/c/a/t/Cat.html" rel="nofollow">http://example.com/articles/c/a/t/Cat.html</a>,
  Get the location in the address bar to show <a href="http://example.com/encyclopedia/Cat.html" rel="nofollow">http://example.com/encyclopedia/Cat.html</a></p>
  
  <p>This also needs to work so that if a link is clicked or someone types in <em>"example.com/encyclopedia/Cat.html"</em>, the server will look for the file in <em>"/articles/c/a/t/Cat.html"</em>, yet still serve the shorter URI in the address bar.</p>
  
  <p>I understand this may involve some heavy .htaccess voodoo to accomplish, or perhaps that it would be better to use a PHP script to serve this purpose.</p>
  
  <p>So far I have the following in my .htaccess:</p>
  
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
  Options +FollowSymLinks
  RewriteEngine On
  RewriteRule ^encyclopedia/(.*)\.html$ articles/$1.html [NC]
  RewriteCond %{THE_REQUEST} ^GET\ articles/(.*)
  RewriteRule ^articles/(.*) /encyclopedia/$1 [L,R=301]
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>However with this code, it only works by going to <em>"example.com/encyclopedia/c/a/t/Cat.html"</em> and showing the proper page, and when you go to <em>"/articles/c/a/t/Cat.html</em> it still doesn't rewrite it as <em>"/encyclopedia/"</em>, it just stays the same.</p>
  
  <p><strong>Edit</strong> - By removing the <code>GET\</code> part from the <code>RewriteCond</code> and removing the leading forward-slash from <code>/encyclopedia/$1</code> in the following line, any requests to <em>"/articles/c/a/t/Cat.html"</em> are correctly redirected to <em>"/encyclopedia/c/a/t/Cat.html"</em>.  I am still at a loss trying to remove the "/c/a/t" part though. **</p>
  
  <p>I've tried using the following two rules to remove the "c/a/t/" part:</p>
  
  <pre><code>RewriteRule ^encyclopedia/((.)(.)(.).*)\.html$ articles/$2/$3/$4/$1.html [NC]
  RewriteRule ^articles/(.)/(.)/(.)/(.*) /encyclopedia/$4 [L,R=301]
  </code></pre>
  
  <p>But with no success as I'm sure what's happening is I'm getting the capital "C" from "Cat.html" and putting that in as <em>"/articles/C/a/t/Cat.html"</em> which will obviously not work.</p>
  
  <p>I've been looking around studying .htaccess RewriteRule and RewriteCond for days but I still haven't been able to figure this out and been BHOK enough to cause a few migraines.</p>
  
  <p>Would this be better accomplished using a PHP script? Or can this voodoo be easily enough accomplished via only .htaccess rules?</p>