Have Apache Force File Downloads

Published on May 1, 2009, 2:27 p.m.

I have a Django app that lets users upload files. Any kind of file. It's nice that Apache will let me force file downloads based on the files extension.
<LocationMatch "\.(gz|tar|pdf|docx|doc|xls|xlsx|bz2|zip)$">
SetHandler None
Header set Content-Disposition attachment
</LocationMatch>

So, in my HTML/templates: all I have to do is this:
<a href="SomFile.docx">Some File</a>

comments powered by Disqus