Re: Blocking certain referrers

This is a discussion on Re: Blocking certain referrers within the Apache Web Server forums, part of the Web Server and Related Forums category; "Ian.H [dS]" <ian@WINDOZEdigiserv.net> wrote in message news:pufqhvca741fnmrbemsd1b333bjq51q95m@4ax.com... > Many apps ...


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 07-22-2003
djc
 
Posts: n/a
Default Re: Blocking certain referrers

"Ian.H [dS]" <ian@WINDOZEdigiserv.net> wrote in message
news:pufqhvca741fnmrbemsd1b333bjq51q95m@4ax.com...
> Many apps allow / have the ability to put whatever they like for a
> header.


Ian, thanks for the warning but I know all about this already and this is
not what I'm concerned with.

> RewriteCond %{HTTP_REFERER} (first-site.com|second-site.com) [NC]


I'm aware of this regexpr method of using alternatives too, but this is
sorta messy for lots of URL's. I was hoping to see something like

RewriteCond %{HTTP_REFERER} xyz.com [NC]
RewriteCond %{HTTP_REFERER} abc.com [NC]
RewriteCond %{HTTP_REFERER} def.com [NC]
RewriteRule ...

Which could match any of the top three conditions, but I guess the regexpr
method will have to do.

--
djc



  #2 (permalink)  
Old 07-22-2003
patpro
 
Posts: n/a
Default Re: Blocking certain referrers

In article <3f1d4d6d$0$26530$afc38c87@news.optusnet.com.au> ,
"djc" <dj@c> wrote:

> I'm aware of this regexpr method of using alternatives too, but this is
> sorta messy for lots of URL's. I was hoping to see something like
>
> RewriteCond %{HTTP_REFERER} xyz.com [NC]
> RewriteCond %{HTTP_REFERER} abc.com [NC]
> RewriteCond %{HTTP_REFERER} def.com [NC]
> RewriteRule ...
>
> Which could match any of the top three conditions, but I guess the regexpr
> method will have to do.


I may have a clue on this, but unfortunately it's mostly speculation. I
don't master SetEnv nor Redirect yet...

I use this .htaccess to prevent people to link to my images from their
own site (bandwidth thieves) :

SetEnvIfNoCase Referer "^http://www.patpro.net/" locally_linked=1
SetEnvIfNoCase Referer "^http://www.patpro.net$" locally_linked=1
SetEnvIfNoCase Referer "^http://patpro.net/" locally_linked=1
SetEnvIfNoCase Referer "^http://patpro.net$" locally_linked=1
SetEnvIfNoCase Referer "^$" locally_linked=1
<FilesMatch "\.(gif|png|jpe?g)$">
Order Allow,Deny
Allow from env=locally_linked
</FilesMatch>

It's not what you're looking for, but the methodology could be the same.
You could for example write :

SetEnvIfNoCase Referer "*xyz.com*" redirect=1
SetEnvIfNoCase Referer "*abc.com*" redirect=1
SetEnvIfNoCase Referer "*def.com*" redirect=1
....
<Directory />
RewriteCond env=redirect [NC]
RewriteRule filename.exe http://www.fbi.gov/ [R,L]
</Directory>

Be carefull, it's mostly conceptual code, exact syntax must be validated.
SetEnv directives must be one level up from the level you'll use the
env. variable "redirect"

hth,

patpro
  #3 (permalink)  
Old 07-22-2003
patpro
 
Posts: n/a
Default Re: Blocking certain referrers

In article <patpro.pouet-9C8E3B.17223822072003@news.wanadoo.fr>,
patpro <patpro.pouet@archange.fr> wrote:

> You could for example write :
>
> SetEnvIfNoCase Referer "*xyz.com*" redirect=1
> SetEnvIfNoCase Referer "*abc.com*" redirect=1
> SetEnvIfNoCase Referer "*def.com*" redirect=1
> ...
> <Directory />
> RewriteCond env=redirect [NC]
> RewriteRule filename.exe http://www.fbi.gov/ [R,L]
> </Directory>
>
> Be carefull, it's mostly conceptual code, exact syntax must be validated.
> SetEnv directives must be one level up from the level you'll use the
> env. variable "redirect"



ok, I'll add a correction here, after reading through the Rewrite doc,
I've found out that you can definitely use environment variables as
RewriteCond. Syntaxe is :

RewriteCond %{ENV:redirect} 1

patpro
  #4 (permalink)  
Old 07-22-2003
patpro
 
Posts: n/a
Default Re: Blocking certain referrers

In article <3f1d4d6d$0$26530$afc38c87@news.optusnet.com.au> ,
"djc" <dj@c> wrote:

> I'm aware of this regexpr method of using alternatives too, but this is
> sorta messy for lots of URL's. I was hoping to see something like
>
> RewriteCond %{HTTP_REFERER} xyz.com [NC]
> RewriteCond %{HTTP_REFERER} abc.com [NC]
> RewriteCond %{HTTP_REFERER} def.com [NC]
> RewriteRule ...
>
> Which could match any of the top three conditions, but I guess the regexpr
> method will have to do.



after reading the rewrite doc I've found that :

-------
'ornext|OR ' ( or next condition)
Use this to combine rule conditions with a local OR instead of the
implicit AND. Typical example:

RewriteCond %{REMOTE_HOST} ^host1.* [OR]
RewriteCond %{REMOTE_HOST} ^host2.* [OR]
RewriteCond %{REMOTE_HOST} ^host3.*
RewriteRule ...some special stuff for any of these hosts...

`Without this flag you would have to write the cond/rule three times.
--------

I guess you can add NC to OR this way : [OR, NC]

patpro
  #5 (permalink)  
Old 07-23-2003
djc
 
Posts: n/a
Default Re: Blocking certain referrers

Perfect. Thanks!

--
djc

"patpro" <patpro@elena.patpro.net> wrote in message
news:patpro-8E7231.19551422072003@biggoron.nerim.net...
> In article <3f1d4d6d$0$26530$afc38c87@news.optusnet.com.au> ,
> "djc" <dj@c> wrote:
>
> > I'm aware of this regexpr method of using alternatives too, but this is
> > sorta messy for lots of URL's. I was hoping to see something like
> >
> > RewriteCond %{HTTP_REFERER} xyz.com [NC]
> > RewriteCond %{HTTP_REFERER} abc.com [NC]
> > RewriteCond %{HTTP_REFERER} def.com [NC]
> > RewriteRule ...
> >
> > Which could match any of the top three conditions, but I guess the

regexpr
> > method will have to do.

>
>
> after reading the rewrite doc I've found that :
>
> -------
> 'ornext|OR ' ( or next condition)
> Use this to combine rule conditions with a local OR instead of the
> implicit AND. Typical example:
>
> RewriteCond %{REMOTE_HOST} ^host1.* [OR]
> RewriteCond %{REMOTE_HOST} ^host2.* [OR]
> RewriteCond %{REMOTE_HOST} ^host3.*
> RewriteRule ...some special stuff for any of these hosts...
>
> `Without this flag you would have to write the cond/rule three times.
> --------
>
> I guess you can add NC to OR this way : [OR, NC]
>
> patpro



  #6 (permalink)  
Old 07-27-2003
Joachim Ring
 
Posts: n/a
Default Re: Blocking certain referrers

> I'm aware of this regexpr method of using alternatives too, but this is
> sorta messy for lots of URL's. I was hoping to see something like
>
> RewriteCond %{HTTP_REFERER} xyz.com [NC]
> RewriteCond %{HTTP_REFERER} abc.com [NC]
> RewriteCond %{HTTP_REFERER} def.com [NC]
> RewriteRule ...
>
> Which could match any of the top three conditions, but I guess the regexpr
> method will have to do.


you might want to read the docs to RewriteCond a bit further than the
nocase flag:

RewriteCond %{HTTP_REFERER} xyz.com [NC,OR]
RewriteCond %{HTTP_REFERER} abc.com [NC,OR]
RewriteCond %{HTTP_REFERER} def.com [NC]
RewriteRule ...

should do the trick. if you have multiple RewriteCond's without the OR
flag, they have all to be satisfied (implicit AND), which doesn't
happen in your example.

joachim
 
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 11:19 AM.


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