How to force download files via .htaccess?

Member

by deron , in category: Third Party Scripts , 4 months ago

How to force download files via .htaccess?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by darrion.kuhn , 2 months ago

@deron 

To force download files via .htaccess, you can use the following directives:

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


This directive tells the server to treat the specified file types (in this case, PDF, XLS, and DOC files) as binary files that should be downloaded rather than displayed in the browser.

  1. Header set Content-Disposition attachment


This directive adds a Content-Disposition header to the response, telling the browser to treat the file as an attachment that should be downloaded rather than displayed.


You can add these directives to your .htaccess file to force download files of specific types. Remember to adjust the file extensions and types as needed for your specific requirements.