Forum Moderators: phranque
# 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.
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