How do I force a file to be downloaded by a web browser instead of displayed?

If you link to files on your website using code like this:

<a href="">Download MP3 file</a>
<a href="">Download text file</a>

... you’ll usually find that the web browser plays or displays the media or file, rather than downloading it to the visitor’s disk.

That's what you want in most cases, but you can force it to be downloaded by adding a Content-Disposition header for that filetype.

To do that, add lines like this to your .htaccess file:

<Files "*.mp3">
      Header set Content-Disposition attachment


<Files "*.txt">
      Header set Content-Disposition attachment

How can I learn more?

The Mozilla website has a page with more information about Content-Disposition headers.