How to force your website to download a file (rather than opening)

07/05/2013

I wanted to add a download link to one of my products. The file was an Windows Installer Package (*.msi).

However, FireFox started to open the file on the browser rather than downloading it so when my visitors tried to download the installer they would rather see some gibberish on the browser because FireFox was trying to “open” the MSI file.

There’s a simple fix.

Just add following line to your .htaccess file so that your website will force your browser to download this type of files than trying to open them.

# force download
AddType application/octet-stream .msi

You can use this method for any type of files. Just add another copy of this line and change the last three characters to your preferred file extension.

e.g. Following code will force browsers to download any *.jpg, *.bat, or *.config files as well

# force download
AddType application/octet-stream .msi
AddType application/octet-stream .jpg
AddType application/octet-stream .bat
AddType application/octet-stream .config

Menol

ILT

This entry was posted in Blogging, General Computing and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *