title: How do I redirect if a PDF is requested from a given directory with .htaccess?
body: <p>I have a bunch of PDFS in: /uploads/dashboard/</p>
  
  <p>What I'd like to do is, if a PDF is requested from this directory, redirect to a script which checks if the user's current session allows them to access the PDF. If the user is allowed, the script serves the PDF.</p>
  
  <p>Here's where I am:</p>
  
  <pre><code>RewriteCond %{REQUEST_URI}/dashboard \.(pdf)$ [NC]   # If filename ends with .pdf and is in the 'dashboard' directory
  RewriteRule ^(.*)$ dl/$1 [L,R]              # Redirect the user to the auth script
  </code></pre>
  
  <p>However, I keep getting a 404 error with the current code.</p>
  
  <p>This is a Zend Framework application with PHP 5.3 Below are the full contents of my .htaccess:</p>
  
  <pre><code>php_flag magic_quotes_gpc Off
  
  SetEnv APPLICATION_ENV development
  
  RewriteEngine On
  
  # Force trailing slash
  RewriteCond %{REQUEST_URI}/dashboard \.(pdf)$ [NC]    # If filename ends with .pdf or .cdr
  RewriteRule ^(.*)$ dl/$1 [L,R]              # Redirect the user to the other site
  
  RewriteCond %{REQUEST_URI} !.(jpe?g|gif|png|js|css|swf|flv)$ [NC]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_METHOD} !=POST
  RewriteCond %{REQUEST_URI} !(.*)/$
  RewriteRule ^(.*)$ %{REQUEST_URI}/ [L,R=301]
  
  RewriteCond %{REQUEST_URI} .(jpe?g|gif|png|js|css|swf|flv)$ [NC,OR]
  RewriteCond %{REQUEST_FILENAME} -s [OR]
  RewriteCond %{REQUEST_FILENAME} -l [OR]
  RewriteCond %{REQUEST_FILENAME} -d
  RewriteRule ^.*$ - [NC,L]
  RewriteRule ^.*$ index.php [NC,L]
  </code></pre>
  
  <p>How might I achieve this?</p>
  
  <p>Many thanks</p>