Categories: Tips & Tricks

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:

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

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

Pradeep

Share
Published by
Pradeep

Recent Posts

Update Google AMP Cache with Perl

While implementing Google AMP (Accelerated Mobile Pages) for your website, it might occur to you…

6 years ago

Don’t buy Reliance Jio’s JioFi Device or JioPhone – Avoid at all cost

Thinking of buying the JioFi device by reliance or to be precise any device by…

7 years ago

Solution for Copy Paste or right click disabled in Websites Chrome

Do you hate those pesky javascripts. Majority of the banking, utility bill payment etc so…

9 years ago

Sync personal ebooks with notes, bookmarks reading position on your Kindle

So amazon has this amazing feature called whispersync : If you read the same Kindle…

10 years ago

Google Authenticator: Moving To A New Phone

Getting a new HTC One left me wondering how will I move Google Authenticator from…

11 years ago

Electronic Arts Free Games! Free ITunes Gift Vouchers

Get Bad Company 2, ME: Infiltrator, etc for free Free Games you can get today:…

11 years ago