I have a pdf link that opens in a new tab, but the new pdf tab response header content-type is "text/html; charset=UTF-8" and the page is blank. If I hard refresh, the content-type becomes "application/pdf".
I've tried adding these into my httpd.conf and still no change:
<FilesMatch "\.(?i:pdf)$">
ForceType application/pdf
Header set Content-Disposition attachment
</FilesMatch>
<LocationMatch "\.(?i:pdf)$">
ForceType application/pdf
Header set Content-Disposition inline
</LocationMatch>
following these answers: Problem with opening pdf file in site
https://stackoverflow.com/a/31939133/9062782
Is there a way to make sure the new tab pdf always opens with application/pdf?
Related
How to use apache AddType to map "text/css;charset=utf-8" to "text/css". So that the response header will look like.
In the response header:
From - Content-Type: text/css;charset=utf-8
To - Content-Type: text/css
I need to remove charset=utf-8 from the response header using AddType in apache.
It depends on how the original charset was added.
As #JoopEggen correctly said, RemoveCharset can undo the effects of character set associations for given extensions.
Another case is when the charset was specified in the configuration file by, say, AddDefaultCharset utf-8. Then you can undo this in your .htaccess with AddDefaultCharset off.
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?
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…
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.
we have an application which downloads the files from the server. After the download them it needs to save it, for that it uses the filename paramter which is comming from the responce header.
When i'm using the standart PHP download.php?id=downloadID i can set the headers with no problem.
The task now is that on the client server they do not have any php available,
i need to set the filename inside of the responce header.
here is the htaccess what i have:
<FilesMatch "\.(?i:pdf)$">
Header set Content-Type: application/octet-stream
Header set Content-Disposition: "attachment; filename=FILE_NAME.pdf"
</FilesMatch>
And i have no idea how to parce the file name dynamicaly to the header using htaccess.
I've google it looked for it but still no solution.
Any suggestions?
I have no idea if it works, but this would be my first attempt.
RewriteRule [^/]+\.pdf$ - [E=FILENAME:$0]
<FilesMatch "\.(?i:pdf)$">
Header set Content-Type application/octet-stream
Header set Content-Disposition "attachment; filename=%{FILENAME}e"
</FilesMatch>
EDIT Seems some apache installs prefix the env variable with REDIRECT_
RewriteRule [^/]+\.pdf$ - [E=FILENAME:$0]
Header set Content-Type application/octet-stream env=REDIRECT_FILENAME
Header set Content-Disposition "attachment; filename=%{REDIRECT_FILENAME}e" env=REDIRECT_FILENAME
Above code doesn't work out of the box. In my case, I needed another internal redirect.
But why would you need to set the filename in the header if the request URL contains the filename too? All browsers will save the file with under the name in the URL. So going to /path/test.pdf will result in browsers suggesting the filename test.pdf.