Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

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

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

Full Member

10+ Year Member

joined:Dec 9, 2002
posts: 234
votes: 0

Thanks to a combination of Mint statistics and Awstats, Iíve found that Iím getting a lot of downloads of a specific song of mine.

The link seems to be direct to the mp3 file so they donít 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 "\.(mp3¶pdf)$">
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)$ http:// mysite.com/mint/pepper/tillkruess/downloads/tracker.php?uri=http://%{HTTP_HOST}%{REQUEST_URI}&force

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...

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

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
votes: 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.



    Join The Conversation

    Moderators and Top Contributors

    Hot Threads This Week

    Featured Threads

    Free SEO Tools

    Hire Expert Members