Forum Moderators: phranque

Message Too Old, No Replies

where's the typo?

         

lucy24

1:24 am on Sep 21, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm trying to figure out why a rule failed.

Background: I've had this pair in my htaccess for ages to deal with my robotic Ukrainian friends. They've got some favorite IPs; I put in the forged referers as a fallback.

RewriteCond %{HTTP_REFERER} www\.trafficfaker\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} \.(ua|su|mobi)/ [NC]
RewriteRule . - [F]

RewriteCond %{HTTP_REFERER} \.ru/ [NC]
RewriteCond %{HTTP_REFERER} !(google|yandex)\.ru [NC]
RewriteRule . - [F]


This has always worked as intended: lock out anyone who claims to have been referred by sites in the Ukraine or Soviet Union (a tld that I have never seen except in forged referers), and same for Russia unless they're coming in via an authorized search engine. The seemingly benign "\.mobi" is because I've never met it in real life, only as part of the Ukrainians' repertoire. And trafficfaker got thrown into the same rule just for convenience. ("Don't like your face" principle. I have never figured out what they're supposed to do.)

So how did someone giving images.yandex.ua/yandsearch as referer get in? Am I overlooking something embarrassingly obvious?

I've discarded Explanation A: that .htaccess read my mind and figured out that I would not have excluded yandex.ua if I had known such an entity existed. In case anyone wondered, the search string-- in Cyrillic-- was for something like "rats in art", and led to a couple of appropriate jpgs.

Postscript:
The .htaccess has now relocated .ua to the second rule, which says

RewriteCond %{HTTP_REFERER} \.(ru|ua)/ [NC]
RewriteCond %{HTTP_REFERER} !(google|yandex)\.(ru|ua)/ [NC]


I wanted to put %1 at the end of the second Cond, but couldn't find any hard evidence that you're allowed to :(

g1smd

8:42 am on Sep 21, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes, you can use %1 from the final previously matched condition in the next condition or in the RewriteRule target.

g1smd

5:49 pm on Oct 29, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Correction. You can use $1 and %1 in conditions, but only "on the left":

RewriteCond $1 <pattern>


RewriteCond %1 <pattern>

lucy24

11:15 pm on Oct 29, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Heh.

Can I do this?

RewriteCond %{HTTP_REFERER} ^ebooks(/\w+/\w+)\.html
RewriteRule ^ebooks%1\.html goaway.html [L]


(The uncaptured parts are to keep the server from wasting its time checking the Condition in situations where the problem doesn't arise.)