Page is a not externally linkable
- Code, Content, and Presentation
-- Perl Server Side CGI Scripting
---- A Close to perfect .htaccess ban list


andreasfriedrich - 1:25 pm on Sep 26, 2002 (gmt 0)


So, this might be better as far as I can see:
RewriteCond %{HTTP_USER_AGENT} .*httrack.* [NC,OR]

You are right in mentioning that the matching should be case insensitive (the NC flag). The '.*', however, is not neccessary, since in

RewriteCond %{HTTP_USER_AGENT} httrack [NC,OR]
the pattern is not anchored anywhere (startŠend of string). The engine will try to match the pattern anywhere in the string.

With '^httrack' the pattern is anchored at the beginning, with httrack$ at the end of the string. When you anchored your pattern at the start and end you would need the '.*' if you wanted to match httrack in a string that is not just 'httrack'. Your pattern would need to look like this: '^.*httrack.*$'. Note that this pattern does not make sense, unless you would want to grab the substring before and after the httrack.

To sum up, here is a chart of the four options mentioned above. NA = not anchored; BA = anchored at beginning; EA = anchored at end; MS = modified suggestion.

1. achttrackac (NA: +; BA: -; EA: -; MS: +;)
2. htTracKacac (NA: +; BA: +; EA: -; MS: +;)
3. aacaHttrack (NA: +; BA: -; EA: +; MS: +;)

Note that '.*' will match the '' string, since the quantifier * greedily (rather more than less) matches 0 or more times.

Andreas


Thread source:: http://www.webmasterworld.com/perl/687.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com