Greenguy's Board

Greenguy's Board (http://www.greenguysboard.com/board/index.php)
-   Programming & Scripting (http://www.greenguysboard.com/board/forumdisplay.php?f=15)
-   -   Anti Hotlinking (http://www.greenguysboard.com/board/showthread.php?t=50059)

Mr Spock 2008-11-14 01:43 AM

Anti Hotlinking
 
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 05: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:
Code:

RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?altlab\.com/ [NC]
RewriteRule .*\.(jpe?g|gif|bmp|png)$ nohotlink.gif [L]


pc 2008-11-14 06: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 06:35 AM

And there is more here

cd34 2008-11-14 11:17 AM

Quote:

Originally Posted by Mr Spock (Post 428905)
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 01: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 02: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

Code:

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

Code:

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:

Code:

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]



All times are GMT -4. The time now is 02:04 PM.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc