Force Files to Download Instead of Opening

Written by Nilpo in Apache | 13 Comments

Have ever wished that you could force a file to download instead of opening in a browser? Some common files like MP3s and PDFs will open in your reader’s browser if the proper parent plugin is installed. Sometimes you want to force them to download the file without having to right-click and save it.

This action can be achieved very easily in Apache by modifying the .htaccess file. You can set it at your domain root to affect your entire site, or you can set it in subdirectories to only affect parts of your site.

All you need to know is your file extension(s). Then add an octet-stream mime type for each. So you might add the following to your .htaccess file.

AddType application/octet-stream .avi 
AddType application/octet-stream .mpg
AddType application/octet-stream .mov
AddType application/octet-stream .pdf

The above example would force a download message and prevent any AVI, MPG, MOV, or PDF file from opening in a browser.

Like the read? Share it!


  • Hey,
    Thanks for the tip! I have been trying to get this result for a few hours now. I have set up HTML email signatures for everyone in my office with a link to download our Vcards, but the vcfs keft displaying in the browser. Thank you very much!

  • No problem at all. I’m glad you found this tip helpful!

  • I need running this at IE6 , but not working.
    not force download in ie6.


  • Great! A simple answer to a common question.


  • Thanks for taking the time to comment. I’m glad you found this useful.

  • Hi.. I don’t know your name,

    but that you very much for your short description about how to display file instead of executing that and how to download instead of opening. That helps me a lot…

    thank you very much..

  • Good afternoon. I’am french speaker. You’re post interest me a lot. I think frensh are according with you. Sorry for languge error 😉

  • Merci, Tim. J’apprécie tes mots aimables. 😉

  • Excellent. Thank you very much for such a simple solution! 😀

  • Thanks,

    It worked like wonder =)
    Simple and clean.

    Good job! +1 to you 😉

  • 5 years later and this blog article is still listed #1 at google for the search:

    apache force file download type

    And this super-simple method fixed my issue immediately. Incredible. I love the internet!


  • Scott,

    Thanks so much for your kind words and for stopping by. I’m glad this worked for you!

  • no script engine for file extention “.Vbs in my computer and i used all ways to fix this problem but i cant

Leave a Reply


Wanna say hello?
Drop us a line!

You'll find us here

1 Microsoft Way,
WA 98052, United States