homepage Welcome to WebmasterWorld Guest from 50.19.33.5
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
How to redirect direct file links to my mp3 download page?
A song of mine is big in Japan! I want to send these visitors to my site
stormy




msg:3544884
 1:57 pm on Jan 10, 2008 (gmt 0)

Thanks to a combination of Mint statistics and Awstats, Ive found that Im getting a lot of downloads of a specific song of mine.

The link seems to be direct to the mp3 file so they dont leave a referrer (or maybe they are blocking it), but it comes from what it seems to be several different portals from Japan.

The question is:

Using .htaccess, how can I allow downloads only if the referrer is my own site, and send visitors that are following a direct mp3 link from another site to my mp3 page?

I'm already using a rewrite rule to track Downloads with a Mint "pepper":

<FilesMatch "\.(mp3pdf)$">
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)$ http:// mysite.com/mint/pepper/tillkruess/downloads/tracker.php?uri=http://%{HTTP_HOST}%{REQUEST_URI}&force
</FilesMatch>

This rule sends all mp3/pdf files through the tracker and forces a download. I suppose I should add some rules before that but I don't know enough about it...

 

jdMorgan




msg:3545073
 5:06 pm on Jan 10, 2008 (gmt 0)

There are several ways to stop direct access, none of them trivial. You cannot use the HTTP_REFERER though, because media players typically do not send a referrer. So that variable will almost always be blank.

Here are two typical methods in outline form:

  • Set a cookie on the page(s) where your site links to your mp3 file(s). This cookie's meaning is "visitor has requested the mp3 from one of my 'authorized' pages." Check for that cookie before serving your mp3 files. The cookie can be set and checked using mod_rewrite or set on the "pages" themselves (if those pages are generated by a script) and checked by your script that serves the mp3 files.

  • Change the URL-path to the mp3 file(s) or the directory in which you keep them. You can do this manually (like once a week) by renaming the file(s) or their directory, or use a script to do it. You will also need to change the links on your pages, and reduce the caching time (or disable caching) on the pages that link to the renamed files for some period of time before making this switchover, so that the links do not appear broken if someone has a copy of the linking page in their browser cache. Be careful with this, as the page caching time must always be short, and you will lose the benefit of caching while you are waiting for your visitor's browser caches to expire before switching the URLs. The cookie method above is superior because while it may be perceived as more difficult to implement, it is much easier to administrate.

    Jim

  • Global Options:
     top home search open messages active posts  
     

    Home / Forums Index / Code, Content, and Presentation / Apache Web Server
    rss feed

    All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
    Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
    © Webmaster World 1996-2014 all rights reserved