Overriding MIME type in .htaccess

1 replies
  • WEB DESIGN
  • |
In general, when I have a PDF file on my website, I want it to be viewed online. However, in some cases, I want it to be downloaded.

The easy way to do this is to stick a .htaccess in a directory that does an AddType for that extension in this directory only:
Code:
 
AddType application/octet-stream .pdf
That naturally makes the PDF file download instead of displaying.

HOWEVER... at the moment, I have a file in a folder which already had other PDFs in it. This was an oversight. I've got links out there which point to PDFs in this folder that I want displayed, and links out there to the one I want downloaded.

So what I want is to say "this PDF file, and ONLY this PDF file, should be served as application/octet-stream" in my .htaccess file. Am I right in thinking this is how to do it?
Code:
 
<Files mypdf.pdf>
   ForceType application/octet-stream
</Files>
#htaccess #mime #overriding #type
  • Profile picture of the author Voon
    Seems right to me. Have you tested yet?

    Normally I would put SetHandler and ForceType together, eg.:

    HTML Code:
    #force download *.pdf
    <FilesMatch ".(?i:pdf)$">
      SetHandler application/octet-stream
      ForceType application/octet-stream
    </FilesMatch>
    
    #force view mypdf.pdf
    <Files "mypdf.pdf">
      SetHandler application/pdf
      ForceType application/pdf
    </Files>
    Signature

    .

    {{ DiscussionBoard.errors[1325527].message }}

Trending Topics