Solved

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

Posted on 2010-08-24
8
427 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
 
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now