A download link can ask a browser to save a file instead of displaying it in the page. This guide explains how to request that behaviour for selected files on an Apache website.

Set a download response header

Back up the relevant .htaccess file first. Apache must support mod_headers and allow the directive in this directory.

To request downloads for PDF files in the chosen directory, add:

<FilesMatch "\.pdf$">
    Header set Content-Disposition "attachment"
</FilesMatch>

Save the file and test a PDF link. Check that the response includes Content-Disposition: attachment and that the site has no server errors. Restore the previous configuration if the directive is not supported.

This applies to all matching files in the configuration’s scope. Do not apply it to files that visitors should view normally. An application or proxy may set its own response headers and need a separate change.

For a file on the same website origin, you can also use the HTML download attribute:

<a href="/downloads/guide.pdf" download>Download the guide</a>

Browsers generally restrict this attribute for links to another website. Browser settings can also affect whether a download prompt appears.

Changing a file’s MIME type to application/octet-stream is not necessary for this method. NGINX does not read .htaccess files; configure its response headers separately.