Forum Moderators: phranque

Message Too Old, No Replies

Adding Code To Htaccess To Block Java

         

snooprock

2:25 pm on Aug 3, 2006 (gmt 0)

10+ Year Member



Hi everyone, I am going to cut and paste the following code in my htaccess file to block those thieving java bots.

# Block java and Python URLlib except from Google and Yahoo
RewriteCond %{HTTP_USER_AGENT} ^(Python[-.]?urllib¦java/?[1-9]\.[0-9]) [NC]
RewriteCond %{REMOTE_ADDR}!^207\.126\.2(2[4-9]¦3[0-9])\.
RewriteCond %{REMOTE_ADDR}!^216\.239\.(3[2-9]¦[45][0-9]¦6[0-3])\.
RewriteRule .* - [F]

However, all of my htaccess file is mostly cut and paste so I dont understand the coding. Here is the first part of my htaccess file, can someone kindly tell me where to paste the above code into my existing code below

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST}!^www\.mysite\.com [NC]
RewriteRule (.*) [mysite.com...] [R=301,L]

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^Alligator [OR]
RewriteCond %{HTTP_USER_AGENT} ^attach [OR]
RewriteCond %{HTTP_USER_AGENT} ^BackWeb [OR]

I really appreciate the help.

jdMorgan

4:19 pm on Aug 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It would be a very good idea for you to do a bit of research and *learn* what all of this means; Because every site and server is different, it's almost impossible for us to tell you a 'one right way' to do anything.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

The fastest way to get up to speed is to take your code one directive or regular-expressions sequence at a time, and look up the meaning in the documents cited above. It gets much easier after the first few lines.

Just as an example, RewriteEngine on should appear once, and at the very top of your mod_rewrite code.

A single incorrect character in an .htaccess directive or in a regular expression can bring your server down until you fix it. For this reason, I cannot recommend a 'cut and paste' approach to using mod_rewrite.

As another example, you've got three RewriteConds at the end, but no RewriteRule, so those will do nothing.
You'll need to add a rule similar to the one in the first rule you posted, to return a forbidden response.

Also, the last RewriteCond in a "stack" of RewriteConds -- the one that precedes the RewriteRule-- *must not* have an [OR] flag on it.

Jim

snooprock

4:30 pm on Aug 3, 2006 (gmt 0)

10+ Year Member



Thanks for the reply JD. I know I need to take the time to learn the coding and it is not fair for me to ask people to do my work for me. I just thought it would be a cut and paste deal and I could move on to my next fire to put out and learn the coding at another time. I will take the time to learn it as advised. Thanks again.