adamshields
asked on
Force the download of PDF from third party URL using mod_rewrite or similar
We have a CDN provider that provides PDF files though for some reason they do not progressively download as they would if being download by a Apache web server. There is not a way from the CDN side of providing a method to force downloading of files rather then opening by default. I can handle this in Apache if the file were hosted locally by using:
AddType application/octet-stream .pdf
or<FilesMatch "\.(?i:pdf)$">
ForceType application/octet-stream
Header set Content-Disposition attachment
</FilesMatch>
but we are not hosting the file but instead providing a redirect to the CDN. Is there a way to force a redirected link to download rather than open? Below is our current rewrite rule which in short takes any requested file in the dl directory and requests it from the CDN. Can we control the remote behavior?RewriteRule ^/dl/(.*)$ http://c0002.cdn1.cloudfiles.rackspacecloud.com/$1 [R=302,L]
You should use mod_proxy to change the headers
ASKER
Can you elaborate or provide an example?
Hi,
let the browsers download the pdf from you and you creating a redirection to the remote host and supply the right header.
The idea is to use the following directives, probably with some tweak
ProxyPass /dl/ http://c0002.cdn1.cloudfiles.rackspacecloud.com/
+
AddType application/octet-stream .pdf
let the browsers download the pdf from you and you creating a redirection to the remote host and supply the right header.
The idea is to use the following directives, probably with some tweak
ProxyPass /dl/ http://c0002.cdn1.cloudfiles.rackspacecloud.com/
+
AddType application/octet-stream .pdf
ASKER
Would this effect the CDN caching or speed since it has to proxy through my host?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That's what I was thinking. We are using it for bandwidth in this scenario. Guess we'll stick with ZIP files as the CDN properly prompts for download. Unless you can think of any other workarounds?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the insight.