Force Files to Download rather than Open in browser

There are certain circumstances where it’s desirable to force files hosted on an Apache web server to download rather than rendering in the browser. This can be accomplished using the following .htaccess file…

<FilesMatch ".+\.*$">
  SetHandler !
  ForceType application/octet-stream
</FilesMatch>

The SetHandler ! line prevents server-side execution of file types such as .php and .cgi.

TheĀ ForceType… line causes the browser to treat files such as .pdf and .html as non-renderable, thus initiating a download.

References:

https://www.myguysolutions.com/…
https://stackoverflow.com/…
https://forum.howtoforge.com/…

Leave a Reply

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