Force Download Specific Files with Apache & Htaccess

At time we want visitors to download instead of viewing the file instead of viewing inside their browser. As a visitor I have faced problems with PDF files at many sites where I wanted to download the PDF file and view it separately because viewing the PDF inside the browser slows down the browser and sometimes causes the browser to crash.

So, If you want to force people to download a file or all files in a specific directory and so on, if is very easy to do so with the help an Apache directive which sets the response header ‘Content-Disposition’ to ‘attachment’, see the examples below:

<Files *.pdf>
Header set Content-Disposition attachment
</Files>

<Directory /var/www/html/images>
Header set Content-Disposition attachment
</Directory>

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.

search engine optimization