Forum Moderators: DixonJones

Message Too Old, No Replies

block visitor by Agent and IP using .htaccess

         

pixelkitty

5:56 am on Dec 2, 2003 (gmt 0)

10+ Year Member



I would like to block a certain User Agent from accessing my sites, but only if they also come from a set IP range.

I tried SetEnvIf but that only blocks the User Agent String and does not discriminate via IP.

Basically, what I want to do is:

If {ip="this IP range"} AND {user agent="this user agent string"} then DENY access ELSE ALLOW access.

Thats the simplest way I can explain it, but I cant work out a way to do it using .htaccess.

Im open to other methods if there are any.

cheers and thanks.

dcrombie

11:54 am on Dec 3, 2003 (gmt 0)



This seems to work on our server:

RewriteCond %{REMOTE_ADDR} ^64.62.XXX.YYY [OR]
RewriteCond %{REMOTE_ADDR} ^62.62.XXX.ZZZ
RewriteCond %{HTTP_USER_AGENT} "some\ user\ agent"
RewriteRule .* - [F,L]

This reads as: IF you come from EITHER of the ip addresses, AND you're using "some user agent" THEN you can't enter.
;)