ghacks Technology News

How to setup Hotlink Protection

Hotlinking is a technique that is frowned upon on the Internet. This happens if you upload a file to your webserver and someone else links to that file directly effectively using your bandwidth to display and / or spread the file on his website. This happens most often with images but it could also be happening with all other files such as zip or pdf.

The best way to stop someone hotlinking your files is to setup a htaccess file a directory that you want to protect. All subdirectories are protected as well by this. If you use a webhosting account you should make sure that you can actually use .htaccess files on it before you try and implement this feature.

To use them you simply upload a file called .htaccess to a directory on your website and edit it with the following information to prevent hotlinking:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?ghacks.net [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ – [NC,F,L]

You have to edit the domain name of course and add possible other filetypes to the list in the fourth line. If you have another domain that should be allowed to hotlink your files you simply add the third line again and edit the domain name accordingly.

If you have a WordPress blog and can’t use .htaccess you could use the WordPress plugin called Hotlink Protection which basically does the same thing but does not allow the addition of other domain names.

Enjoyed the article?: Then sign-up for our free newsletter or RSS feed to kick off your day with the latest technology news and tips, or share the article with your friends and contacts on Facebook or Twitter.

Related Articles:

Unsuggester and some Apache .htaccess tips
Howto Setup a Ftp Server in 5 Minutes
MSI or EXE Setup
Setup Ubuntu to browse Windows network by hostname
Speed Up WordPress With Better Permalink Rewrite Code



About the Author:Martin Brinkmann is a journalist from Germany who founded Ghacks Technology News Back in 2005. He is passionate about all things tech and knows the Internet and computers like the back of his hand. You can follow Martin on Facebook or Twitter.

Author: , Wednesday August 1, 2007 -
Tags:, ,


Responses so far:

  1. African Boy says:

    As long as only the owner site can access the file, nice piece of information.

  2. Martin says:

    African Boy that’s why the name of the site is mentioned in the code :P

Leave a Reply   Follow Ghacks   Subscribe To Comment Rss

Subscribe without commenting

© 2005-2012 Ghacks.net. All Rights Reserved. Privacy Policy - About Us