PDA

View Full Version : Anti Hotlinking


Mr Spock
2008-11-14, 02:43 AM
To stop hotlinking put the follwong code in my htaccess ,

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(www\.)?fotopiccanti.it [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} ^http://.*$
RewriteRule \.(jpe?g|gif|bmp|png)$ - [F]


What it ended up doing was block all images on my server , so if I made a freesite - the images that I hosted on my server would not appear, any idea why?

dunc
2008-11-14, 06:21 AM
I'm not an expert in these matters - but I did have a similar problem a few years ago and used the code below... but if I remember when researching - it was a different syntax dependent upon the server setup:
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?altlab\.com/ [NC]
RewriteRule .*\.(jpe?g|gif|bmp|png)$ nohotlink.gif [L]

pc
2008-11-14, 07:29 AM
what I have in my site:


## DISABLE HOTLINKING
RewriteEngine on
# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?aaaaa.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?bbbbbbb.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?cccccccc.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?ddddddd.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?eeeeee.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?fffffff.com/.*$ [NC]
RewriteRule \.(gif|jpg|jpeg|png|js|css)$ - [F]


a,b,c,d,e,anf are exceptions

pc
2008-11-14, 07:35 AM
And there is more here
(http://www.greenguysboard.com/board/showthread.php?t=47803&highlight=hotlinking+code)

cd34
2008-11-14, 12:17 PM
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(www\.)?fotopiccanti.it [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} ^http://.*$
RewriteRule \.(jpe?g|gif|bmp|png)$ - [F]


The problem here is that:

RewriteCond %{HTTP_REFERER} ^http://.*$

matches any request that has a referrer. So, if the referrer is not from your site, and it is not blank, and it comes from any site, block the image.

Removing that one line will fix the problem.

Mr Spock
2008-11-14, 02:25 PM
I tried that and still blocks my images - I only want to stop fotopicanti from linking to pics , but it seems like any requests get blocked |huh

Should save on bandwidth though |jester|

cd34
2008-11-14, 03:36 PM
That rule is only allowing fotopiccanti.it to link your images, so, its the reverse of what you want.

There are two ways to do it.

1) block all hotlinking allowing your domain


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


2) deny specific sites from hotlinking


RewriteEngine on
RewriteCond %{HTTP_REFERER} fotopiccanti.it [NC]
RewriteRule .* - [F]


A better rule that is likely to catch a few potential ways that they can potentially work around your rules is:


RewriteEngine on
# leave this line in allow empty referrers, remove to disallow empty referrers
RewriteCond %{HTTP_REFERER} !^$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(.*@)?([a-z0-9-]+\.)*yourdomain\.com(:[0-9]+)?(/.*)?$ [NC]
RewriteRule .*\.(asf|mpg|mpeg|wmv|avi|rm|gif|jpe?g|png|zip)$ - [NC,F,L]