UBB.Dev
I remember seeing this a while ago here in the admin forum, but since I can't view that now, thought I'd ask. I know some people who have sites on our site network and people are linking to their images (car blueprints) and stealing bandwidth. I know it involves the rewrite engine. I'd like to possible block all .gif and .jpg files from being linked and then replacing the images with a 'You are linking to a file on our servers and stealing our bandwidth. Please cease and desist." image.

Cheers,
Dan
Nevermind, did some searches on google and put this together and it works fairly well:

Code
RewriteEngine on

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://www.my-site.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://my-site.com/.*$ [NC]
RewriteRule .*.(jpg|gif)$ illegaly-linked-image [L]
Posted By: RandyM Re: .htaccess to restrict remote image linking - 07/31/2002 6:01 AM
What is the actual syntax for the link to the image in this line?

Quote
code:
Code
RewriteRule .*.(jpg|gif)$  illegaly-linked-image        [L]

In other words, do I need to use this.

code:
[qb]
Code
  RewriteRule .*.(jpg|gif)$  !^http://www.netwerkin.com/images/dont_steal.jpg$     [L]
[/qb]
Or without the tags around the URL like this?

Quote
quote:
RewriteRule .*.(jpg|gif)$ http://www.netwerkin.com/images/dont_steal.jpg [L]
As an example, here's the one I use:
Code
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)?solareclipse.net/ [NC]
RewriteRule .(gif|jpg)$ http://solareclipse.net/stolen.gif [R,L]
Yes, this does work - the .htaccess is in a subdirectory, so stolen.gif itself isn't filtered. If you want to protect your entire site, you should be able to get away with creating a subdirectory, then .htaccessing it with RewriteEngine off.
Is there a way to use this but exempt some specific files located in the directory your protecting and also allow some specific websites?
Quote
quote:
Originally posted by usr bin geek:
Is there a way to use this but exempt some specific files located in the directory your protecting and also allow some specific websites?
I'm not sure about exempting some files, but if you want to allow certain specific other sites, just add some more conditions:

code:
[qb]
Code
RewriteCond %{HTTP_REFERER} !^http://(www.)?site1.com/ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www.)?site2.com/ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www.)?site3.com/ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www.)?site4.com/ [NC]
[/qb]
etc... wink
I *THINK* that you can do this, but I'm not sure:


RewriteEngine off
© UBB.Developers