Rewrite rules for all sites in httpd_config.conf ?

#1
Hello,
I want to block some bad user agent strings for all my websites.
Instead of keeping the rewrite rules in each of my virtual host,
can I keep this code in httpd_config.conf so that it applies to all my websites?

Code:
# Global rewrite rules

rewrite {

    enable                  1

    autoLoadHtaccess        0

    RewriteCond %{HTTP_USER_AGENT} seozoom [NC,OR]

    RewriteCond %{HTTP_USER_AGENT} GPTBot [NC,OR]

    RewriteCond %{HTTP_USER_AGENT} Bytedance [NC]

   RewriteRule .* - [F,L]

}
If this is not correct, please suggest correct method.
Thanks
 
Last edited:

Krishna

New Member
#3
Hi,
Thanks for reply.
I created this file :
/usr/local/lsws/conf/badbots.conf

Code:
RewriteCond %{HTTP_USER_AGENT} "testbadbot1|testbadbot2" [NC]
RewriteRule .* - [F,L]
where should I include this in httpd_conf.conf so that the rewrite rules work for all my sites?

should I include this line before all virtual hosts
include /usr/local/lsws/conf/badbots.conf
or at the end ?

Please suggest.
Thanks
 

Krishna

New Member
#6
rewrite code to block bad bots is working if I use the code in each of my virtual hosts vhconf.conf

Code:
RewriteCond %{HTTP_USER_AGENT} "seozoom|badBot" [NC]
RewriteRule .* - [F,L]

but global rewrite rules are not working.
I want to place the code in httpd_config.conf and it should stop bad bots for all my virtual hosts.

Please suggest without using .htaccess files and without modsecurity.
Thanks a lot.
 
Last edited:

Cold-Egg

Administrator
#7
You are right, can not just include it in the server config file, need to include it in the virtual host config file.
 
Top