Solved

Force the download of PDF from third party URL using mod_rewrite or similar

Posted on 2010-08-24
8
436 Views
Last Modified: 2012-05-10
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
Comment
Question by:adamshields
  • 4
  • 4
8 Comments
 
LVL 9

Expert Comment

by:fcontrepois
ID: 33520218
You should use mod_proxy to change the headers
0
 
LVL 3

Author Comment

by:adamshields
ID: 33520307
Can you elaborate or provide an example?
0
 
LVL 9

Expert Comment

by:fcontrepois
ID: 33520515
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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 3

Author Comment

by:adamshields
ID: 33520656
Would this effect the CDN caching or speed since it has to proxy through my host?
0
 
LVL 9

Accepted Solution

by:
fcontrepois earned 500 total points
ID: 33520772
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
 
LVL 3

Author Comment

by:adamshields
ID: 33520825
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
 
LVL 9

Assisted Solution

by:fcontrepois
fcontrepois earned 500 total points
ID: 33523171
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
 
LVL 3

Author Closing Comment

by:adamshields
ID: 33524165
Thanks for the insight.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to count occurrences of each item in an array.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question