CSV file opening in browser even after setting Apache Header - apache

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.

Related

Apache - set application MIME type based on URL or directory

I have some images in my content whose url look like
http://www.example.com/sites/default/files/cdn/2014/10/08/w3V7WGRjaj5FUXx6wM5LIA4eyfmmB0grX0cIvPw2qf-O1mhQ2qwYPEHddAeVer62LLkZFrEV7fSQCxSR-J_CjPxncwLfbmjkdKNE_Gt1eENqMD5ikc9Bwl-NhSdePmjn2g
These are image files, with no extension.
They render as images on my webhost.
I moved to a different server, and currently when the same url is opened, the browser offers the image as text file for download.
I believe the application/mime type is not being set to image by the new apache server.
i tried adding a htaccess snippet as
<Directory "sites/default/cdn/*">
Header append Vary: Accept-Encoding
AddType image/png .png
</Directory>
And also tried several other combinations like giving a specific directory instead of a *, etc. But no luck so far.
Any pointers?

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

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?

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.

Apache download files with specific extension

I have download directory on apache webserver. Files in this directory have specific extensions. For example *.yyy and *.zzz. But all these files are renamed .zip or .tar.gz
I've tested in different brawsers and havn't got any problems.
But some users tell that they get source of packages, not download.
I've created.htaccess
AddType application/zip .zzz
AddType application/x-gzip .yyy
But when I try to download aaa.yyy in MS Internet Explorer it try to save not aaa.yyy but aaa.gz
How to force browsers download files and not to change extensions?
<FilesMatch "\.(zzz|yyy)$">
ForceType application/octet-stream
Header set Content-Disposition attachment
</FilesMatch>
Force type tell browsers that you dont know file type. So they are not going to do any thing stupid. Second line will tell them to download this file.