• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 468
  • Last Modified:

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

0
adamshields
Asked:
adamshields
  • 4
  • 4
2 Solutions
 
fcontrepoisCommented:
You should use mod_proxy to change the headers
0
 
adamshieldsAuthor Commented:
Can you elaborate or provide an example?
0
 
fcontrepoisCommented:
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





0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
adamshieldsAuthor Commented:
Would this effect the CDN caching or speed since it has to proxy through my host?
0
 
fcontrepoisCommented:
All requests - particularly download - would go through your host, so if you use the cloud for bandwidth then this is not a good solution. If you choose cloud for space then yes.

The "problem" is by redirecting (301)  the browser to rackspace you loose control on the requests for pdf.
0
 
adamshieldsAuthor Commented:
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?
0
 
fcontrepoisCommented:
After receiving a 301 the browser will just create a new request to the 301 destination so you don't have any possibilities to change anything, it's between them.
0
 
adamshieldsAuthor Commented:
Thanks for the insight.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now