Set Content-Disposition header to attachment only on files in a certain directory?

Like @gumbo said, put the .htaccess file in the highest level folder you want to affect. and those settings will trickle down to sub folders. You may also want to make sure the headers module is enabled before using this in your htaccess file. The following line will generate an error if the headers module is not enabled:

Header set Content-Disposition attachment

here’s an example that forces download of mp3 files only if the headers module is enabled:

<IfModule mod_headers.c>
    <FilesMatch "\.(mp3|MP3)$">
        ForceType audio/mpeg
        Header set Content-Disposition "attachment"
        Allow from all
    </FilesMatch>
</IfModule>

Note: it does not enable the module, it just ignores anything inside the IfModule tags if the module is not enabled.

To enable apache modules you’ll either need to edit your httpd.conf file or in wamp server you can click the wamp tray icon and select “Apache -> Apache Modules -> headers_module” or make sure it is checked.

Leave a Comment