Force mp3, pdf and other files to download (Apache)

If your website visitor clicks on a URL that links to a file, such as mp3, mp4, doc, pdf, etc., the file will be displayed/played inside the browser if the browser supports that particular format. This is inconsistent across different browsers as not all browsers support the same file formats.

To make experience more consistent you can force files to be downloaded rather than be displayed inside browsers.

To do this create .htaccess file on your Apache web server in the same directory where the files in question are saved. It should have following content: 

<FilesMatch "\.(?i:doc|pdf|mp3)$">
  Header set Content-Disposition attachment
</FilesMatch>

doc|pdf|mp3 - file extensions that you are forcing to download.

This will work in Joomla, Wordpress, Drupal and other CMS as long as they run on Apache web server.

Newsletter

Subscribe to receive occasional updates on new posts.
Your email will not be used for any other purpose and you can unsubscribe at any time.
Please wait