Link to home
Start Free TrialLog in
Avatar of adamshields
adamshieldsFlag for United States of America

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

Open in new window

or
<FilesMatch "\.(?i:pdf)$">
  ForceType application/octet-stream
  Header set Content-Disposition attachment
</FilesMatch>

Open in new window

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]

Open in new window

Avatar of Frank Contrepois
Frank Contrepois
Flag of United Kingdom of Great Britain and Northern Ireland image

You should use mod_proxy to change the headers
Avatar of adamshields

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





Would this effect the CDN caching or speed since it has to proxy through my host?
ASKER CERTIFIED SOLUTION
Avatar of Frank Contrepois
Frank Contrepois
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the insight.