Blocking user agent via .htaccess, not working

I’ve noticed a lot of unidentified bots crawling my site, all with the user agent string beginning with “Java”.I want to block them via .htaccess, but don’t seem to have any success in doing so. This is my code:


RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^Java.*
RewriteRule ^/(.*)$ /$1 [F,L]

I have a FF extension that allows me to change my user agent identifier, and I’ve changed it to “Java/1.6.0_27” just like one of the bots I noticed. I’ve verified that it actually changes the string. But if I go to my site, the pages shows up as normal and I am not served a 403 error as I should be.

I have other rewrite rules that work just fine, so I don’t think it’s a server configuration problem. What am I doing wrong?

For some reason this still isn’t working, despite that nearly every tutorial I’ve found online says this is how to do it. Anybody have an idea why?
Appreciate it!

RewriteCond %{HTTP_USER_AGENT} ^Java [NC] RewriteRule .* - [F,L]You don’t want to re-write the inbound request to anything specifically… Also the useragent doesn’t need to be finished, you aren’t specifying an end.

You might want [NC] to ignore case too.