How to make Apache force download of files (in .htaccess)

Apache: How to make Apache force download of files (in .htaccess)

If you want to force the download of files (octet-stream), you can use this code. Edit the file types as required.

  1. AddType application/octet-stream .doc .docx .xls .pdf

You can use this to force PDFs to download and not show in the browser:

  1. AddType application/octet-stream .pdf

If you want to force other file types (such as Word Document, Excel, etc) just edit the file type

webdevetc profile pic
webdevetc

I am a 29 year old backend web developer from London, mostly focusing on PHP and Laravel lately. This (webdevetc.com) is my blog where I write about some web development topics (PHP, Laravel, Javascript, and some server stuff). contact me here.



More...


Comments and discussion about How to make Apache force download of files (in .htaccess)

Found this interesting? Maybe you want to read some more in this series?

Or see other topics in the Apache language

Or see other languages/frameworks:
PHP Laravel Composer Apache CentOS and Linux Stuff WordPress General Webdev and Programming Stuff JavaScript
Or see random questions

How to check if an object or variable is an array, in JS?

How to disable file hotlinking in Apache with .htaccess

How to generate an array for a dropdown (with ['key' => 'value']) suitable for a dropdown, from a Laravel collection of Eloquent objects?

How to get a route to directly show a view?

How to merge/concat two arrays together in JS?

How to set up an alias to map one directory to another destination

How to see all of the options for an artisan command?

How to get table column names from a database table in Eloquent?

An overview of every main PHP array function

How to Extract Query String (from a URL) Into an Associative Array in PHP