Link to external file, forcing a download

New to mod_rewrite? This is a good place to start.

Link to external file, forcing a download

Postby embezzler » Sun May 24, 2009 9:27 am

I have been playing around with mod_rewrite and php these last days, but I do not find the correct way to solve the following situation. I would like to have a script, running on my own server, which links to an external file, like an mp3, but forcing the redirect in the background to appear as the name I choose.

For example, if there is a file like http://www.manufacturer.com/files/original.mp3, I would like to be able to present it as http://server.com/new/local.mp3.

Using mod_rewrite, I am able to remove .php extension from new.php and use php to do a redirect to the original.mp3, appearing as local.mp3. When downloading this file however, the client, like a browser, still saves it as original.mp3. Is there a way to force it to use the local.mp3 filename, without download the file first to my local machine, so not wasting any bandwith?
embezzler
 
Posts: 1
Joined: Sun May 24, 2009 9:16 am

Postby richardk » Sun May 24, 2009 10:43 am

Do you have permission?

You could do it using mod_proxy and mod_rewrite (the P RewriteRule flag). However, this would use your servers transfer and bandwidth because the request would go user -> you -> manufacturer --> you --> user.

Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^new/([^/]+\.mp3)$ http://www.example.com/files/$1 [P,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 116 guests

cron