February 12, 2011

Htaccess protect your downloads

by Karine in Intermediate with no response

It's really annoying when you post downloads and other websites just steal the direct link and post it on their own websites right ? With htaccess, you can redirect those direct links to your main website (if someone tries to download a file off your website from an other website, he will be redirected to your website). ;)

Create an htaccess file and paste this inside :

# Protect bandwidth
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?your-website.com/.*$ [NC]
RewriteRule ^download/([^/]+)$ http://your-website.com [R=302,L]
</ifModule>
# Protect bandwidth

This code will only work if your download links use this pattern : http://your-website.com/download/ID

Just edit "download" to adapt it to your website and don't forget to change the URL.

If you get a 500 Internal server error, it means something is wrong in your htaccess, check the syntax, or restart.

Be Sociable, Share!

Tags

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.

↑ Back to Top