Bluehost.com Web Hosting $6.95

mod_rewrite anti-leeching problem?

This is a discussion on mod_rewrite anti-leeching problem? within the Apache Web Server forums, part of the Web Server and Related Forums category; Hi, Ok I don't really know anything about mod_rewrite, but want to stop leeching from my website. So I ...


Go Back   Usenet Forums > Web Server and Related Forums > Apache Web Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-23-2006
steve.mckeogh@googlemail.com
 
Posts: n/a
Default mod_rewrite anti-leeching problem?

Hi,

Ok I don't really know anything about mod_rewrite, but want to stop
leeching from my website. So I found a anti leeching mod_rewrite script
that works, but has one serious problem.

firstly the syntax is:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule \.(jpe?g|gif|png)$ images/restricted.gif [L]

now if someone links to link it shows the restricted.gif which is
great. But the serious problem I have is that if I open up a new
browser and just type in "www.mydomain.com" it replaces every image on
my site with the restricted.gif. Obvioulsy if I click a link and go to
another page on my site then all the images appear ( I assume cos the
HTTP_REFERER is now my domain).

The strange thing is I've only noticed this problem on my PC here at
work? Never had that problem on my pc at home?

Any ideas what it could be?

Thanks for your time!

Steve M

  #2 (permalink)  
Old 01-23-2006
Robert Ionescu
 
Posts: n/a
Default Re: mod_rewrite anti-leeching problem?

steve.mckeogh@googlemail.com wrote:
[...]
>
> RewriteEngine On
> RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain\.com/ [NC]
> RewriteCond %{HTTP_REFERER} !^$
> RewriteRule \.(jpe?g|gif|png)$ images/restricted.gif [L]
>
> now if someone links to link it shows the restricted.gif which is
> great. But the serious problem I have is that if I open up a new
> browser and just type in "www.mydomain.com" it replaces every image on
> my site with the restricted.gif.


Remove the trailing slash of the rerferer

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain\.com [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule \.(jpe?g|gif|png)$ /images/restricted.gif [L]

--
Robert
  #3 (permalink)  
Old 01-23-2006
steve.mckeogh@googlemail.com
 
Posts: n/a
Default Re: mod_rewrite anti-leeching problem?

Cheers Rob, that seems to have worked.

Only problem is I cant seem to get it to link to the restricted.gif
anymore, it just shows a broken image on external sites now. So instesd
Im doing:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://mydomain.com [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mydomain.com [NC]
RewriteRule [^/]+.(gif|jpg)$ - [F]

Does this look ideal? Or could it be better?

ta

  #4 (permalink)  
Old 01-23-2006
Robert Ionescu
 
Posts: n/a
Default Re: mod_rewrite anti-leeching problem?

steve.mckeogh@googlemail.com wrote:
> Only problem is I cant seem to get it to link to the restricted.gif
> anymore, it just shows a broken image on external sites now.


If you're using the rules in .htaccess configuration files, try to
exclude the file and send also a redirect

> Im doing:
>
> RewriteEngine On
> RewriteCond %{HTTP_REFERER} !^http://mydomain.com [NC]
> RewriteCond %{HTTP_REFERER} !^http://www.mydomain.com [NC]
> RewriteRule [^/]+.(gif|jpg)$ - [F]


Why did you change both conditions?
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain\.com
is the same for both new conditions. You should also allow an enpty
referer (which was done by your second condition), because not every one
is able to send a referer (i.e. behind cacheing proxies etc.)

I'd use

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain\.com [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{REQUEST_URI} !^/images/restricted\.gif$
RewriteRule \.(jpe?g|gif|png)$ /images/restricted.gif [R,L]

--
Robert
  #5 (permalink)  
Old 01-23-2006
steve.mckeogh@googlemail.com
 
Posts: n/a
Default Re: mod_rewrite anti-leeching problem?

Hmmm, ok I have added the above and it is now allowing images to show
on external sites. And the reason for that is the line:

RewriteCond %{HTTP_REFERER} !^$

If I remove that and end up with:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain\.com [NC]
RewriteCond %{REQUEST_URI} !^/images/restricted\.gif$
RewriteRule \.(jpe?g|gif|png)$ /images/restricted.gif [R,L]

It works fine? So its the empty referer that seems to be allowing
external sites to use my images still?

Any ideas?

  #6 (permalink)  
Old 01-23-2006
Robert Ionescu
 
Posts: n/a
Default Re: mod_rewrite anti-leeching problem?

steve.mckeogh@googlemail.com wrote:
> Hmmm, ok I have added the above and it is now allowing images to show
> on external sites. And the reason for that is the line:
>
> RewriteCond %{HTTP_REFERER} !^$


Then your referer was empty. Check the HTTP-Re3quest headers or your
access.log, if you're logging in combined format (which contains the
referer). If the referer is empty and you don't allow an empty referer,
all images on your site are blocked if you're really visiting your site.

--
Robert
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:16 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0