Block agent user from 12:30am to 2 am

Viewed 76

I would like to block Twitterbot/1.0 agent user from 12:30am to 2 am cause it visits me a couple of times all night at 0:40am and 1:25 am more or less causing my server to fall 1 minute on both "strange crawling visits".

I have seen this code that says to block all from 4:00pm to 4:59pm and 8am

RewriteEngine On
# Multiple hour blocks
# If the hour is 4 PM or 5 PM or 8 AM
RewriteCond %{TIME_HOUR} ^16|17|08$
# Then deny all access
RewriteRule ^.*$ - [F,L]

I´m not and expert on this kind of codes so how can I block an user agent or some ips instead of all?

Many thanks.

1 Answers

Could you please try following, written with your shown samples. Please make sure to clear your browser cache before testing your URLs.

RewriteEngine ON
RewriteCond %{HTTP_USER_AGENT} Twitterbot/1\.0 [NC]
RewriteCond %{TIME_HOUR}%{TIME_MIN} >=0030
RewriteCond %{TIME_HOUR}%{TIME_MIN} <=0200
RewriteRule ^ - [F,L]

NOTE: Also to check these set of Rules immediately you can keep your current time in these timings places for testing purposes so that you can instantly check them if they are working fine or not. Also change your agent name accordingly in case this is not the exact one in above Rules.

Related