Technistuff: Howto stop hotlinking mp3 files?
  • Have been SLAMMED by hotlinkers in the last month and a half - almost all china and spain - and as a result, bandwidth has doubled to almost two terabytes, and my provider wants me to upgrade beyond my means. In the last day alone, I've used about 6% of my monthly allotment - and the usual tracking tools don't tell me until the next day what's on the "hotlist".

    I know this has been discussed before, but although I'm a brave soul willing to muck around, I can't even find the .htaccess file in my wordpress set-up. Complications arise, too, as I use my server as a web server for emailing files to others, and for using files at work, and I wouldn't want to lose that - nor would I want to muck up feedreader access, HypeM and elbo.ws access, etc.

    Any suggestions?
  • Which hosting company are you with?

    As a general rule you will not be able to see/edit your .htacess via FTP, so the best way to edit it is normally to go into your webspace through the file manager in your hosting control panel.

    There are a few ways to accomplish blocking hotlinking depending on your server setup, just as there are ways to circumvent them. One of these should work:
    (in each case you can replace http://coverlaydown.com/pleasedonthotlink.html with the url to whatever page you want to redirect users to)


    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?coverlaydown.com(/)?.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?hypem.com(/)?.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?hype.non-standard.net(/)?.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?elbo.ws(/)?.*$ [NC]
    RewriteRule .*\.(mp3)$ http://coverlaydown.com/pleasedonthotlink.html [R,NC]



    Options +FollowSymlinks
    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?coverlaydown.com(/)?.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?hypem.com(/)?.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?hype.non-standard.net(/)?.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?elbo.ws(/)?.*$ [NC]
    RewriteRule .*\.(mp3)$ http://coverlaydown.com/pleasedonthotlink.html [R,NC]



    Options +FollowSymlinks
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?coverlaydown.com(/)?.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?hypem.com(/)?.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?hype.non-standard.net(/)?.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?elbo.ws(/)?.*$ [NC]
    RewriteRule .*\.(mp3)$ http://coverlaydown.com/pleasedonthotlink.html [R,NC]



    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?coverlaydown.com(/)?.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?hypem.com(/)?.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?hype.non-standard.net(/)?.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?elbo.ws(/)?.*$ [NC]
    RewriteRule .*\.(mp3)$ http://coverlaydown.com/pleasedonthotlink.html [R,NC]
  • Thanks, Tim. Had been seeing versions of this code floating around, but mostly for jpg images - nice to know it works for .mp3, too.

    I'm with a private hosting company - imountain.com, which serves me well, has great support, and provides solar-powered virtual private servers. Highly recommended for power users with high but relatively predictable bandwidth needs.

    Questions:

    1. If my current .htaccess file's first line looks like this:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L],

    does that tell you which of these would work for me? Or is trying all four in sequence harmless?

    2. Before I try it: if I want to be able to email links to hosted files so that someone can click on the link in email and download directly, do I need to include gmail/google in my exclude list above?
  • 1. To be honest I don't play around much .htaccess so couldn't really tell you.
    The first one is the only one I've ever actually used myself and it has worked for me so I would just try all four in sequence until you find one that works for you. Never have more than one in your .htaccess at a time, but trying them individually shouldn't cause issues.

    2. That depends on how each email provider shows their referrer, but as a general rule yes you should add exceptions for hotmail/gmail/yahoomail/etc to be sure.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!