Good Blog, Karl

woof.

Forcing MS Office files to download

Every time clients start putting up links to Microsoft Office files on their sites, I’m sent scrambling around my hard drive with a find ~/Sites -name ".htaccess" -exec grep "ms-word" '{}' \; -print command or searching the googles for htaccess force download ms-word. Fortunately, it doesn’t take too long to find what I’m looking for:

<pre><code class="hljs apache"><span class="hljs-keyword">AddType</span> application/vnd.ms-word.document.macroEnabled.12 .docm
<span class="hljs-keyword">AddType</span> application/vnd.openxmlformats-officedocument.wordprocessingml.document docx
<span class="hljs-keyword">AddType</span> application/vnd.openxmlformats-officedocument.wordprocessingml.template dotx
<span class="hljs-keyword">AddType</span> application/vnd.ms-powerpoint.template.macroEnabled.12 potm
<span class="hljs-keyword">AddType</span> application/vnd.openxmlformats-officedocument.presentationml.template potx
<span class="hljs-keyword">AddType</span> application/vnd.ms-powerpoint.addin.macroEnabled.12 ppam
<span class="hljs-keyword">AddType</span> application/vnd.ms-powerpoint.slideshow.macroEnabled.12 ppsm
<span class="hljs-keyword">AddType</span> application/vnd.openxmlformats-officedocument.presentationml.slideshow ppsx
<span class="hljs-keyword">AddType</span> application/vnd.ms-powerpoint.presentation.macroEnabled.12 pptm
<span class="hljs-keyword">AddType</span> application/vnd.openxmlformats-officedocument.presentationml.presentation pptx
<span class="hljs-keyword">AddType</span> application/vnd.ms-excel.addin.macroEnabled.12 xlam
<span class="hljs-keyword">AddType</span> application/vnd.ms-excel.sheet.binary.macroEnabled.12 xlsb
<span class="hljs-keyword">AddType</span> application/vnd.ms-excel.sheet.macroEnabled.12 xlsm
<span class="hljs-keyword">AddType</span> application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx
<span class="hljs-keyword">AddType</span> application/vnd.ms-excel.template.macroEnabled.12 xltm
<span class="hljs-keyword">AddType</span> application/vnd.openxmlformats-officedocument.spreadsheetml.template xltx</code></pre>

I suppose I could set them all to application/octet-stream or some such if I truly wanted to force the download, but I’m pretty sure that doing it the long way will allow the user to choose whether to open the file in the appropriate Office Application or save it. In any case, the clients seem to love it. Microsoft Word to your mother!