Apache – make a file downloadable

As well known, Apache is a web server application. To give a basic summary, you can place files on your apache webserver and browse them afterwards in your webbrowser. Now Apache uses MIME types to know how to display various types of file, for example .php has to be rendered by PHP, html can be processed by the Apache server and etc.

This technique can prove troublesome if you want to use your web hosting as a download folder. For example you have a folder full of .xml or .txt files that need to be downloaded from you hosting instead of viewed in your browser. To do this you can erase the MIME type in the server preferences but this solution does this for the full webserver. So other folders will also promp a downloadable file instead of viewing it.

To enable this only for one folder, you can use the .htaccess file.
In your FTP program or through the shell navigate to the folder you want to use as your download folder and create or open the .htaccess file.
Then add the following line to the file

Just change the “file type” to the extension of your file excluding the dot. For example if you want to download .txt files your .htaccess will be as followed

Afterwards just reload your browser page and the file will be downloadable.

Have fun

Geef een antwoord

Het e-mailadres wordt niet gepubliceerd. Vereiste velden zijn gemarkeerd met *