This is a discussion on <IfDefine env=...> & RewriteRule/Redirect - Question within the Apache Web Server forums, part of the Web Server and Related Forums category; Ok I'm trying to setup an anti leech protection. I already got one working with a .htaccess file just ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Ok I'm trying to setup an anti leech protection. I already got one
working with a .htaccess file just setting an eviormente variable depending on the referer and if it is not set just deny the user. *code* SetEnvIf referer ^http://gallery\.amonamarth\.de let_me_in Order Deny,Allow Deny from all Allow from env=let_me_in *code* Easy one, but I want it a bit more tricky, the anti leech is primary for the pictures, so the .htaccess file is located in my /img/ directory. I also got another directory with an image, this is /images/antileech.jpg. So what I want is that when someone for example posts a picture somewhere in a forum located on my server in the /img/ directory, the enviorment variable is not set so the rewrite jumps in and sends him /images/antileech.jpg, so he knows he'd host the picture by himself. So I crawled through some stuff, what I tried is the following: *code* SetEnvIfNoCase Referer ^http://gallery\.amonamarth\.de let_me_in <IfDefine env=!let_me_in> RewriteRule ^/img/.*$ http://www.amonamarth.de/images/antileech.jpg </IfDefine> *code* I have problems with the <IfDefine env=*> and with the RewriteRule thing, I tried also different combinations. <IfDefine env=!let_me_in> <IfDefine !env=let_me_in> <IfDefine !let_me_in> None is working right, as I thought it should. Can you give me the correct form of this? The RewriteRule is also not doing what I want, I'm not too familliar with mod_rewrite yet as I never worked very much with it (I also tried a redirect but also not doing it). So can you help me with that one too? Thanks |
|
|||
|
On Fri, 04 Mar 2005 22:53:23 +0100, in alt.apache.configuration,
Alexander Scheurer <mail@aspepex.net> wrote: <snip> >Easy one, but I want it a bit more tricky, the anti leech is primary for >the pictures, so the .htaccess file is located in my /img/ directory. I >also got another directory with an image, this is /images/antileech.jpg. >So what I want is that when someone for example posts a picture >somewhere in a forum located on my server in the /img/ directory, the >enviorment variable is not set so the rewrite jumps in and sends him >/images/antileech.jpg, so he knows he'd host the picture by himself. >So I crawled through some stuff, what I tried is the following: > >*code* >SetEnvIfNoCase Referer ^http://gallery\.amonamarth\.de let_me_in ><IfDefine env=!let_me_in> >RewriteRule ^/img/.*$ http://www.amonamarth.de/images/antileech.jpg ></IfDefine> >*code* > >I have problems with the <IfDefine env=*> and with the RewriteRule >thing, I tried also different combinations. ><IfDefine env=!let_me_in> ><IfDefine !env=let_me_in> ><IfDefine !let_me_in> >None is working right, as I thought it should. Can you give me the >correct form of this? >The RewriteRule is also not doing what I want, I'm not too familliar >with mod_rewrite yet as I never worked very much with it (I also tried a >redirect but also not doing it). So can you help me with that one too? Try using RewriteCond (untested, but I use similar rules in my config): RewriteCond %{HTTP_REFERER} !^http://gallery\.amonamarth\.de [NC] RewriteRule ^/img/ http://www.amonamarth.de/images/antileech.jpg FYI, I've read that some browsers can be configured not to supply the HTTP_REFERER header. You will be prohibiting them from access your images. HTH, Jim |
|
|||
|
Jim Hayter wrote:
> Try using RewriteCond (untested, but I use similar rules in my > config): > RewriteCond %{HTTP_REFERER} !^http://gallery\.amonamarth\.de [NC] > RewriteRule ^/img/ http://www.amonamarth.de/images/antileech.jpg > > FYI, I've read that some browsers can be configured not to supply the > HTTP_REFERER header. You will be prohibiting them from access your > images. Thanks alot you sent me to the right direction, after trying a bit I asked Google for help on the RewriteCond and found this page: http://www.trafficklau.de/htaccess.html (German) They got 2 solutions for my problem. 1. RewriteCond *code* RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http://(www\.)?trafficklau\.de(/.*)?$ [NC] RewriteRule \.(gif|jpg|GIF|JPG)$ http://www.trafficklau.de/images/ersatz.gif [R,L] *code* 2. SetEnvIf(NoCase) *code* <Files ~ "\.(gif|jpe?g|png)$"> ErrorDocument 403 http://www.trafficklau.de/ersatzgrafik.gif SetEnvIfNoCase Referer "^http://www.trafficklau.de" local_ref=1 SetEnvIfNoCase Referer "^http://trafficklau.de" local_ref=1 Order Allow,Deny Allow from env=local_ref </Files> *code* I think I would have never come to the conclusion to just add the ErrorDocument 403 to the thing I already had. Thanks again Alex |