Greenguy's Board


Go Back   Greenguy's Board > Programming & Scripting
Register FAQ Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
Old 2008-11-14, 01:43 AM   #1
Mr Spock
You can now put whatever you want in this space :)
 
Mr Spock's Avatar
 
Join Date: Nov 2006
Location: Vulcan
Posts: 695
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?
Mr Spock is offline   Reply With Quote
Old 2008-11-14, 05:21 AM   #2
dunc
You can now put whatever you want in this space :)
 
dunc's Avatar
 
Join Date: Feb 2007
Location: Australia
Posts: 658
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]
dunc is offline   Reply With Quote
Old 2008-11-14, 06:29 AM   #3
pc
Shift Out / X-On
 
pc's Avatar
 
Join Date: Jul 2007
Location: unknown
Posts: 2,298
Send a message via ICQ to pc
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 is offline   Reply With Quote
Old 2008-11-14, 06:35 AM   #4
pc
Shift Out / X-On
 
pc's Avatar
 
Join Date: Jul 2007
Location: unknown
Posts: 2,298
Send a message via ICQ to pc
And there is more here
pc is offline   Reply With Quote
Old 2008-11-14, 11:17 AM   #5
cd34
a.k.a. Sparky
 
cd34's Avatar
 
Join Date: Sep 2004
Location: West Palm Beach, FL, USA
Posts: 2,396
Quote:
Originally Posted by Mr Spock View Post
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.
__________________
SnapReplay.com a different way to share photos - iPhone & Android
cd34 is offline   Reply With Quote
Old 2008-11-14, 01:25 PM   #6
Mr Spock
You can now put whatever you want in this space :)
 
Mr Spock's Avatar
 
Join Date: Nov 2006
Location: Vulcan
Posts: 695
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

Should save on bandwidth though
Mr Spock is offline   Reply With Quote
Old 2008-11-14, 02:36 PM   #7
cd34
a.k.a. Sparky
 
cd34's Avatar
 
Join Date: Sep 2004
Location: West Palm Beach, FL, USA
Posts: 2,396
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]
__________________
SnapReplay.com a different way to share photos - iPhone & Android
cd34 is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:53 PM.


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