Forum Moderators: phranque
Here's what it looks like:
---------------------------
In the following examples you're going to see what the complete RewriteCond line looks like. I used one of my favorite nasty bots, HTTrack, for the example.
RewriteCond %{HTTP_USER_AGENT} HTTrack
Above you see a typical ban line in an .htaccess file. What this line will do is ban any visitor (bot or not!) from viewing your site if the visitor's User Agent has the term HTTrack anywhere in the entire User Agent string.
RewriteCond %{HTTP_USER_AGENT} HTTrack [NC]
This is the same line with a [NC] added to the back. This means No Case, or case insensitive. This would also ban the lowercase httrack, where the first version WOULD NOT.
RewriteCond %{HTTP_USER_AGENT} ^HTTrack
This line adds a carrot to the front, which designates that the string must start with this term. In this case, HTTracker would be blocked, but myHTTrack would not.
RewriteCond %{HTTP_USER_AGENT} HTTrack$
Here we add a dollar sign to the back and do just the opposite. Now the string must end with this term. myHTTrack would be blocked, but HTTracker would not.
RewriteCond %{HTTP_USER_AGENT} ^HTTrack$ [NC]
You can combine these rules in any way you want. In the above example, the case doesn't matter, since we have the [NC], but only the exact term HTTrack (or httrack, HtTrAcK, HTTRACk, etc) will be banned. HTTracker and myHTTrack will get by because our string MUST start with exactly HTTrack and end with exactly HTTrack to be blocked.
RewriteCond %{HTTP_USER_AGENT} oz [NC]
This is an exteremely bad idea. This line will block any user agent with the two letters O and Z right next to each other in that order. Of course, this would ban anyone using Firefox (Mozilla) right out of the box, and probably hundreds more. It's typically a better idea to be more conservative.
-----------------------------------
I go on to note that I am by no means an expert, they should be extremely careful, and I refer them to a much better source of information (this forum actually) if they would like more information. I wrote it just to give a basic understanding.
Also, when you're running a bunch of Conditions for the same rule and you want a condition to be case insensitive, can you write it like [NC][OR] or do you have to do [NC,OR]?
Thanks again.
[edited by: Duskrider at 2:48 am (utc) on May 2, 2007]
The only error I saw is that you add a "carat," not a "carrot" to the beginning of a pattern to start-anchor it... :) If you intend to use this as a tutorial, you might want to introduce the terms "pattern," "substitution," and "anchoring."
Jim