Forum Moderators: phranque
Since initially implementing this script on my site I've had to relocate to different servers 3 times. On the first server the script worked exactly as explained in the posts (different host than I have now). On the second server it didn't seem to work at all but I was so immersed in other problems that I didn't have time to look into it. On this last server relocation suddenly the script seemed to start working again - but I hadn't tested it yet.
When the bad bot gets caught the script writes the following line at the top of the htaccess script (example):
SetEnvIf Remote_Addr ^66\.xxx\.xxx\.xx$ getout # Fri Aug 1 09:23:36 2003 Mozilla/4.0 (compatible; MSIE 5.0; Windows NT)
I'm on a shared hosting account. I just received an email from my host...
"We have found one of the issues with apache crashing is due to some line end comments you had in your .htaccess file. This was causing apache to crash for one reason or another and also filling up the logs fast."
My host then edited the top of my htaccess file to look like this:
SetEnvIf Remote_Addr ^66\.xxx\.xxx\.xx$ getout
... and also said: "We needed to remove the '#' character and everything after it ... Please do not add this back"
Here are my questions:
--Is my host right about the line generated by this script causing apache to crash?
--Can someone help me understand how the comment line could have caused/contributed to the problem? (I'm very skeptical about his explanation but I just don't understand this stuff unfortunately).
--If he IS right then won't the problem continue the next time the script writes a new bad bot line to the top of my htaccess?
It would seem a more likely explanation that I somehow messed up my own htaccess or the script rather than blame it on the script itself. But considering my ignorance I don't know what to look for. Can anyone help me figure this out? I'm grateful for any assistance.
Change the third line of the script snippet as shown below. This prints the date and user agent in a stand-alone comment line first, and then prints the SetEnvIf directive on the next line. This should eliminate your problem.
# Empty existing .htaccess file, then write new IP ban line and
# previous contents to it
truncate(HTACCESS,0);
print HTACCESS ("\# $date $usragnt\nSetEnvIf Remote_Addr \^$remaddr\$ getout\n");
print HTACCESS (@contents);
HTH,
Jim
Because of this problem, jatar_k has been kind enough to add the script correction to the thread cited above, modified "bad-bot" script blocks site downloads at [webmasterworld.com...]
Thanks, jatar_k!
Jim