title: .htaccess Rewrite direct file access
body: <p>I have been looking all over and I can't find a solution that works for me.</p>
  
  <p>I'm trying to redirect <a href="http://example.com/files/file.ext" rel="nofollow">http://example.com/files/file.ext</a> -> <a href="http://example.com/users/documents/file.ext" rel="nofollow">http://example.com/users/documents/file.ext</a></p>
  
  <p>No matter what I try when I got directly to the file it downloads it. The GET request for the file doesn't show in any of my apache logs either. I have logging on debug.</p>
  
  <p>[Edit]
  The files I'm trying to download are of various types including ppt, pdf, xls, zip, doc, etc. I want to rewrite the filename to the end of the new URI. I am also using CodeIgniter so /users/documents/ is a RESTy uri.</p>
  
  <p>Anyone have a fix?</p>
  
  <p>Here is my .htaccess file:</p>
  
  <pre><code>    &lt;IfModule mod_rewrite.c&gt;
      RewriteEngine On
      Options +FollowSymLinks
      RewriteBase /
  
  
      #Removes access to the system folder by users.
      #Additionally this will allow you to create a System.php controller,
      #previously this would not have been possible.
      #'system' can be replaced if you have renamed your system folder.
      RewriteCond %{REQUEST_URI} ^system.*
      RewriteRule ^(.*)$ /index.php?/$1 [L]
  
      #When your application folder isn't in the system folder
      #This snippet prevents user access to the application folder
      #Submitted by: Fabdrol
      #Rename 'application' to your applications folder name.
      RewriteCond %{REQUEST_URI} ^application.*
      RewriteRule ^(.*)$ /index.php?/$1 [L]
  
      #Checks to see if the user is attempting to access a valid file,
      #such as an image or css document, if this isn't true it sends the
      #request to index.php
  
  
      &lt;IfModule mod_php5.c&gt;
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteRule ^(.*)$ index.php?/$1 [N]
  
          RewriteCond %{REQUEST_URI} ^/files/ [NC]
          RewriteRule ^/files/(.*)$ /users/documents/$1 [L,R=301]
  
  
      &lt;/IfModule&gt;
  
      &lt;IfModule !mod_php5.c&gt;
          RewriteRule ^(.*)$ index.php?/$1 [L]
      &lt;/IfModule&gt;
  
  &lt;/IfModule&gt;
  </code></pre>