How to make files downloadable upon a click on a link

Learn how to force file downloads using the .htaccess file

Updated 4 weeks ago

Make files downloadable upon a click on a link, forcing a download instead of the default browser preview behavior. Normally, clicking a file URL opens it in the browser — you can force it to download instead using the .htaccess file.

Before you start

Force file downloads

Access the File Manager, find the .htaccess file, and open it to edit. Add the snippet of code below, specifying all the preferred file extensions that you want to make downloadable upon a click on the link:

<FilesMatch "\.(avi|mpg|mov|pdf|xls|mp4)$">
    ForceType application/octet-stream
    Header set Content-Disposition attachment
</FilesMatch>

For example, if you’d like to make only the .pdf files downloadable, the line of code would look like this:

<FilesMatch "\.pdf$">
    ForceType application/octet-stream
    Header set Content-Disposition attachment
</FilesMatch>

Save the changes, and that’s it! If you can’t see the changes on your live website, try clearing the cache.