Hotlinking

Status
Niet open voor verdere reacties.

joanne

Terugkerende gebruiker
Lid geworden
31 mrt 2001
Berichten
1.300
Is nieuw voor me. Wist niet dat dit kon.
Las dit verhaal op http://www.biorust.com/tutorials/detail/7/en/


Prevent Hotlinking


If you are one of the many thousands of webmasters who pay for your web hosting, you will no doubt have come across a rather evil practice known as hotlinking. Quite simply, a hotlinker will use HTML to directly link to objects on your server, thus allowing him/her to use your bandwidth, but without the inconvenience of ever having to pay for it. If you own a website with a lot of images or files on it, for example, this can be very costly as it sucks away your bandwidth without giving you a single visitor to your actual HTML site in return. Now, however, you can fight back with a little bit of server-side wizardry.

To stop hotlinkers in their tracks, all you need is a server running Apache with .htaccess files enabled, and a little known module installed called mod_rewrite. All of these things are very common in modern web hosting setups, and can be installed pretty easily if they are not there initially anyway. With all these pieces in place, simply create a file called .htaccess (if you use notepad, beware it doesn't add a .txt extension onto the end) that contains the following code:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain\.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ - [F]

Be sure to replace yourdomain.com with your own domainname and save the file. Now upload the file to the main directory of your website, or the specific subdirectory you want to protect. Remember that the settings in this file will affect any directory you put it into and all subdirectories branching off from it, but not any parent directories. Also make sure you upload this file in ASCII and not binary, and CHMOD it to 644 or you'll run into problems. If you don't know how to CHMOD, just download a decent FTP program like CuteFTP, right click on the file, and select 'change file attributes' or somesuch - that does the same (essentially it just allows the file to be readable by the server but not by any joe public with a browser).

The aforementioned code will just display a broken link if anything but a webpage on your domain refers to it. If you want to be a bit more evil, however, and display an alternate image of your choice instead, use this code:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain\.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ http://www.yourdomain.com/diehotlinker.jpg [R,L]

Just do the same as before and replace yourdomain.com and diehotlinker.jpg with your own settings. Now just upload your new evil image and kiss goodbye to those annoying hotlinkers. Just make sure you configure it correctly before you do anything too nasty though, or you might send your own legitimate visitors some unpleasant images. They might never forgive you for sending them something from www.goatse.cx... :p
 
Goed om weten. :thumb:
Weer iets bijgeleerd. ;)

Greetz : Jer:cool:en.
 
en vertaal dit nu eens naar het Nederlands zodat de mensen die geen engels kunnen lezen ook weten wat hier staat.

je weet wel helpmij.nl de gratis computerhelpdesk van Nederland........dus voor mensen die Nederlands lezen.
 
De vertaling:

Hotlinken voorkomen
Als een andere website-eigenaar afbeeldingen en daarmee dus bandbreedte steelt door direct naar uw afbeeldingen te linken binnen diens eigen website, dan kunt de volgende commando's in het .htaccess bestand plaatsen om dit te voorkomen:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mijndomein.nl/.*$ [NC]
RewriteRule \.(gif|jpg)$ - [F]

Vervang daarbij 'mijndomein.nl' door uw eigen domeinnaam. Met deze code zullen alleen de bezoekers aan 'mijndomein.nl' deze afbeeldingen te zien krijgen. Afbeeldingen op sites die gelinkt zijn zullen niet meer in beeld verschijnen.

Als u echt in een vervelend wilt zijn kunt u zelfs een alternatief bestand in de plaats zetten van de ge-'hotlinkte' afbeeldingen. Bijvoorbeeld een eenvoudig plaatje met de tekst 'stelen is verboden, kom naar mijndomein.nl voor de echte plaatjes'. De volgende code in het .htaccess bestand zorgt daarvoor:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mijndomein.nl/.*$ [NC]
RewriteRule \.(gif|jpg)$ http://www.mijndomein.nl/nietstelen.gif [R,L]

Vergeet niet uw eigen domeinnaam hier in te vullen en het bestand 'nietstelen.gif' te plaatsen.
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan