Last updated: 06 Sep 2010
Using Apache 2 configuration to add Content-disposition headerApache 2 web server has a header manipulation module (
mod_headers) that allows adding required headers to HTTP response.
Content-dispositionheader through web server configuration is easy (albeit not always possible if the need to store the file is dictated by a web application).
What to change in server configuration
mod_headersmodule (it is usually disabled by default). In Debian and Ubuntu Linux distributions this is done using the following command:
- For Linux distributions or other Unix systems not having any additional
module handling infrastructure this can be done by adding the following
line to web servers
LoadModule headers_module /usr/lib/apache2/modules/mod_headers.so
- Then we need to tell web server to send
Content-Dispositionheader for certain situations, for example to make all pdf files to be downloaded instead of open in browser add the following code to your virtual server configuration:
<FilesMatch "\.pdf$"> Header set Content-Disposition attachment </FilesMatch>This will suffice for most modern browsers which will are able to derive the filename from URL by stripping parameters and path information.
- Restart your web server for configuration to take effect.