Have Apache Force File Downloads

Published on 2009-05-01 14:27:00+00:00
apache   django   web  

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>