Forcefully download files on Apache server using .htaccess file

At times we share some files to our users either a PDF or mp3 or any image file like JPEG etc. But, while doing that browser opens that rather that allowing download them directly.
To avail direct download or force download you can add couple of lines in your .htaccess file which will allow user forcefully download the file as soon as they click on some link or download button.

Here is what you will add to your .htaccess file:

The above lines will tell Apache server to allow download forcefully. Above code will allow .mov , .mp3 , .jpg , .pdf to direct download without opening it in browser.
You can add or remove file extension or file types depending on your need.

Leave a Reply

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