Filed Under: Code Snippets

How to force file download via .htaccess

4 September 2010 No Comment Tags:


Share

I haven’t added anything new to this blog for a while, but today I stumbled on a really useful trick that allows you to force a file download of specific file types via .htaccess. More after the break.

Let’s say you want to provide some registry files (.reg) on your website or some videos and MP3′s that users should only download not watch on your server, then this will come in handy.

Create a .htaccess file in your download folder e.g. /downloads/ and then copy and paste this

<Files *.*>
ForceType applicaton/octet-stream
</Files>

This will force the browser (IE, Firefox, etc. all supported) to download the file instead of trying to open it!

I hope this helps some people, because it clearly sucks when people can’t download your files and you did not notice it.







Like our posts? Then subscribe via Mail:

Email:  

Similar Posts:

Leave your response!

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.com.