Forum Moderators: phranque
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} webzip [NC,OR]
RewriteCond %{HTTP_USER_AGENT} flashget [NC,OR]
RewriteCond %{HTTP_USER_AGENT} teltport [NC]
RewriteRule ^(.*) - [F]
But when I test it with webzip 6.0, it doesn't work. I checked my access log and found that HTTP_USER_AGENT was detected as "Mozilla/4.0 (compatible; MSIE 6.0; Win32)". I think this is the reason.
Anyone know how to resolve this problem?
Thanks.
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/4\.0\ \(compatible;\ MSIE\ 6\.0;\ Win32\)$ [OR]
RewriteCond %{HTTP_USER_AGENT} webzip [NC,OR]
RewriteCond %{HTTP_USER_AGENT} flashget [NC,OR]
RewriteCond %{HTTP_USER_AGENT} teltport [NC]
RewriteRule ^(.*) - [F]
Jim
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/4\.0.\(compatible\;.MSIE.6\.0\;.Win32\) [OR]
Here's hoping one version's regex is akin to the other's because the above is the only mod_rewrite language I understand -- and three cheers, it works!
Any character that has a special meaning as a regex token needs to be escaped, such as ".", "(" and ")" in this example. The complete list for regex in mod_rewrite would be $ % ^ * ( ) + { } [ ] ¦ \ . ? Spaces need to be escaped because mod_rewrite treats them as delimiters.
I don't see anything in Ralph's documentation that contradicts this (?) - It's not even mentioned as far as I can see/find. And most of my servers are still Apache 1.3.x.
It doesn't usually hurt anything to escape a character that doesn't need to be escaped, and a space will match the "." pattern, which is why your pattern works.
The pattern I show above is correct, maximally-specific, and optimized, AFAIK.
Jim
And of course, new valid user-agent names appear every week, so there is never an end to this project.
Jim
Shoot. Given the vagaries of mod_rewrite's code and effects, and the near-daily increases in abusive bots and scrapers, I'm feeling darn near whelmed playing catch-up. I already rewrite ALL non-Mozilla UAs but for robots.txt-respecting bots -- and still the bad Mozilla.* variations and cloaks come. There's GOT to be a better way....
Ah, well. That's enough meandering musing for one post, sorry. We now return you to your regularly scheduled Q&A:)