View Single Post
  #2  
Old 02-10-2007, 04:29 PM
Connie
Guest
 
Posts: n/a
#I How to prevent hotlinking with .htaccess

Wikipedia describes hotlinking the following:

Quote:
Inline linking, also known as hotlinking, leeching, or direct linking is the placing of a linked object, often an image, from one site in a web page belonging to a second site. The second site is said to have an inline link to the one where the object is located.
  1. The easiest way: your Webadministration Panel
  2. Do it yourself

Check whether your webhoster offers you the chance to stop hotlinking.
If your webspace sits on an apache server, the chance to stop hotlinking is very good.

If you use CPANEL, you will use the option Hotlink Protection
If you do not find it at first glance, look for the advanced menu.
In that section first you will find a description of Hotlinks and a form to define your rules.

Quote:
HotLink protection prevents other websites from directly linking to files (as specified below) on your website. Other sites will still be able to link to any file type that you don't specify below (ie. html files). An example of hotlinking would be using a <img> tag to display an image from your site from somewhere else on the net. The end result is that the other site is stealing your bandwidth. You should ensure that all sites that you wish to allow direct links from are in the list below. This system attempts add all sites it knows you own to the list, however you may need to add others.
You will define which URLs are allowed to access which fileformats (defined by their extensions) and you will decide which URL will be delivered to all other accesses.

Example: All direct accesses to files with the extension .jpg from the domain myimages.com will be served with the respective file, all other accesses from other domains will be directed to another URL, for example to another image-file.

So you name myimages.com in the list of allowed URLs, the extensions gif,jpg,GIF,JPG in the allowed extensions and the URL for the redirect.

As a result, you will get a .htaccess-file in the root of your server whith rules like these:

Quote:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?myimages.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?myimages.com*$ [NC]
RewriteRule .*\.(gif|jpg|GIF|JPG)$ http://www.myimages.com/donotholtink.jpg [R,NC]
what does this mean?

All accesses to your photo-files from the domain myimages.com will be served correctly, the browser will show these files.

All other accesses, for example a link in a html-file or a forum at www.thisisnotmydomain.com will be redirected to the file donothotlink.jpg at your domain.

The .htaccess-file at www.photografitti.net allows access from a list of domains, all other accesses will be redirected to this file:



This JPG-file tells in german, that the intended image, which should show off here, is stolen from my website www.photografitti.de

here is an excerpt from that .htaccess-file:

Quote:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?avantart.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?avantart.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?avantart.de/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?avantart.de$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?pixelpost.org/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?pixelpost.org$ [NC]
RewriteRule .*\.(gif|jpg|GIF|JPG)$ http://www.zweiterblick.de/aetsch.jpg [R,NC]
what is the effect?

People, who steal your photos will be blamed.
They will learn something from that, I hope.

But still your webserver will deliver a graphic file and these hotlinking people will steal your traffic. But they are not stealing your photos anymore!


Remember, that this is only working with APACHE, not with IE-Servers!

Last edited by Connie; 02-15-2007 at 07:13 PM. Reason: typo