Force PDF download 'only' in Internet Expl

2020-04-21 06:08发布

问题:

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

回答1:

Try this in your .htaccess file

SetEnvIf Request_URI ".pdf$" requested_pdf=pdf

Header add Content-Disposition "attachment" env=requested_pdf