title: Canonical Header Links for PDF and Image files in .htaccess
body: <p>I'm attempting to setup Canonical links for a number of PDF and images files on my website.</p>
  
  <p>Example Folder Structure:</p>
  
  <pre><code>/index.php
  /docs/
      file.pdf
      /folder1/
          file.pdf
      /folder2/
          file1.pdf
          file2.pdf
  /img/
      sprite.png
      /slideshow/
          slide1.jpg
          slide2.jpg
  </code></pre>
  
  <p>Example PDF URL to Canonical URL:
  <code>http://www.example.com/docs/folder1/file.pdf --&gt; http://www.example.com/products/folder1/</code></p>
  
  <p>I am trying to avoid having to put individual .htaccess files in each of the sub-folders that contain all of my images and PDFs. I currently have 7 "main" folders, and each of these folders have any where from 2-10 sub-folders, and most sub-folders have their own sub-folders. I have roughly 80 PDFs, and even more images.</p>
  
  <p>I'm looking for a (semi)dynamic solution where all files in a certain folder will have the Canonical Link set to a single url. I want to keep as much as possible in a single .htaccess file.</p>
  
  <p>I know that <code>&lt;Files&gt;</code> and <code>&lt;FilesMatch&gt;</code> do not understand paths, and that <code>&lt;Directory&gt;</code> and <code>&lt;DirectoryMatch&gt;</code> don't work in .htaccess files.</p>
  
  <p>Is there a fairly simple way to accomplish this?</p>