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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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? |
|
|||
|
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 |