Forum Moderators: phranque
I have a server, let's pretend it is www.myserver.com . I need to have a directory called /downloads that will contain a bunch of subdirectories, loaded with mp3s in it. I want to deny direct access to /downloads and everything in it (files and and folders) except if it is called directly from one of the wepages hosted on www.myserver.com
Ex.: www.myserver.com/myBestSong.mp3 isn't accessible by typing the adress directly in the browser, MediaPlayer or other download software but
<a href="www.myserver.com/downloads/myBestSong.mp3">Listen to my song</a> is accessible only if the link is included in files on my www.myserver.com server.
Is there a way to do this? Maybe the solution i'm searching for concerns a combination of CHMOD w/ .htaccess ... I'm lost here...
Thanks a lot!
So it seems perhaps that:
deny from all
allow from [certain condition]
allow from [certain condition]
allow from [certain condition]
...is be better than blocking specific users.
The key is in the wording in the forst post, "called directly from one of the wepages hosted on www.myserver.com"; This implies referrer-based access control. And referrer-based access control doesn't work if no referrer is provided, and media players do not generally provide any HTTP_REFERER header...
If you deny access unless the referrer is your own server, it fails because no referrer is provided, and therefore the blank value won't match your own hostname.
If you try to allow blank referrers to correct that problem, then since almost all referrers will be blank due to the fact that few media players send that header, the result is that almost everyone is allowed access, and the code doesn't accomplish anything.
There are various alternative approaches: One is to dynamically rename the published URLs (say based on day-of-week/time-of-day), and then use mod_rewrite to dynamically re-connect the dynamic URLs with the actual server filepaths.
Another is to use a script to read and send the mp3 files to the client. Before doing this, the script can check for a short-expiry-time cookie that is set by the visitor actually viewing one of your own pages. If the request is made based on a hotlink on a third-party site, then the cookie won't be set so the cookie check will fail, and you can then provide alternative content, such as a voice message that says, "The site you are visiting has effectively taken our content, and is representing it as their own. To hear this tune, please visit our site at www.example.com. Again that's www.example.com. Thank you."
Jim
So forcing the user agent to provide specific referer=mysite.com headers will block all media players (and browsers that don't control their referer headers properly), and all traffic coming from outside mysite.com, which is what I think RH is trying to do. Or am I really lost?