Forcing download using <filesMatch> in .htaccess not working just for one filetype - apache

Internet Explorer is displaying contents of some files instead of downloading them. I was able to fix this by adding
<FilesMatch "\.(asapt|ob2|cub)$">
ForceType application/octet-stream
Header set Content-Disposition attachment
</FilesMatch>
to .htaccess. It works for .asapt and .cub files, but strangely not for .ob2 (they are still being displayed in-browser). Why?

Related

Force download file and exclude PDF

I want to configure my htaccess for force downloading all files except PDF. For this I tried following:
<FilesMatch "\.(?!pdf)$">
ForceType application/octet-stream
Header set Content-Disposition attachment
</FilesMatch>
But this not working. There are many examples for forcing downloads files, but no for excluding…

Force PDF download 'only' in Internet Explorer

I've been having issues with displaying PDF documents in IE. Other browsers (Chrome, firefox, etc.) are all OK but IE is no good. So my solution is to force the PDF download for IE users ONLY with modifications to the .htaccess file. I have it currently set up to force the PDF download on all browsers, however I want chrome/firefox/etc. users to have the PDF displayed in browser.
Here is my current .htaccess rules:
<FilesMatch "\.(?i:pdf)$">
SetEnvIf Request_URI "\.pdf$" requested_pdf=pdf
Header add Content-Disposition "attachment" env=requested_pdf
</FilesMatch>
Is there a way to utilize BrowserMatch to only set this header when in IE? Or is there another solution using another method? I've had no luck so far.
Thank you in advance!
CentOS | Apache | PHP
Try this in your .htaccess file
SetEnvIf Request_URI ".pdf$" requested_pdf=pdf
Header add Content-Disposition "attachment" env=requested_pdf

How to create direct download link for pdf

I have uploaded a pdf file in ftp server. The following link opens pdf file in the browser.
http://aptform.culinarysuperstars.com/Appointment_static.pdf
How to create a link for pdf file so that it is downloaded directly instead of opening in the browser?
Locate the .htaccess-file on your FTP server. This is usually hidden, so you might have to make sure you can view and edit hidden files. You can then modify it to force downloads instead of showing up in the browser.
Include the following in the file:
AddType application/octet-stream .pdf
I am unsure whether this will work in any browser; if not, try the following in the .htaccess-file:
<FilesMatch "\.(?i:pdf)$">
ForceType application/octet-stream
Header set Content-Disposition attachment
</FilesMatch>
Method 2:
<FilesMatch "\.(pdf)$" >
ForceType application/octet-stream
Header add Content-Disposition "attachment"
</FilesMatch>
This is something you can't really control, it's based on browser/user settings.
If you're able to, you can try sending the header Content-disposition: attachment; filename="Appointment_static.pdf" with the file contents, which might trigger a download dialog rather than the file being shown in the browser, but you can't really rely on that.

CSV file opening in browser even after setting Apache Header

I have a csv file in my server for which I show the link and the user is allowed to download it. But the file is being opened directly in IE9 instead of just showing the link. For other browsers its working correctly. I have also done the following setup in my httpd.conf file for Apache.
<FilesMatch "\.(?i:csv)$">
ForceType application/octet-stream
Header set Content-Disposition "attachment"
</FilesMatch>
This is working correctly in my local machine, the issue is only happening when I run it in a server.

Set Content-Disposition header to attachment only on files in a certain directory?

I've got this this rule in my htaccess file to force linked files to download rather than open in the browser:
<FilesMatch "\.(gif|jpe?g|png)$">
ForceType application/octet-stream
Header set Content-Disposition attachment
</FilesMatch>
Is there a way to alter the RegExp so it only applies to files in a certain directory?
Thanks
Like #gumbo said, put the .htaccess file in the highest level folder you want to affect. and those settings will trickle down to sub folders. You may also want to make sure the headers module is enabled before using this in your htaccess file. The following line will generate an error if the headers module is not enabled:
Header set Content-Disposition attachment
here's an example that forces download of mp3 files only if the headers module is enabled:
<IfModule mod_headers.c>
<FilesMatch "\.(mp3|MP3)$">
ForceType audio/mpeg
Header set Content-Disposition "attachment"
Allow from all
</FilesMatch>
</IfModule>
Note: it does not enable the module, it just ignores anything inside the IfModule tags if the module is not enabled.
To enable apache modules you'll either need to edit your httpd.conf file or in wamp server you can click the wamp tray icon and select "Apache -> Apache Modules -> headers_module" or make sure it is checked.
You will probably need to put the directives in the .htaccess file in the particular directory.
Put it in a <Location> directive, and/or modify the regex to exclude slashes or as appropriate.