php - Bot-blocking code ignored in htaccess? -
i've been trying solve several days now, can't find answer. on shared hosting account i'm using, i'd modify .htaccess
file block bots visiting site. code i've used:
# begin wordpress <ifmodule mod_rewrite.c> rewriteengine on rewritebase / setenvifnocase user-agent .*dotbot.* bad_bot setenvifnocase user-agent .*gigabot.* bad_bot setenvifnocase user-agent .*ahrefsbot.* bad_bot <limit post head> order allow,deny allow deny env=bad_bot </limit> rewriterule ^index\.php$ - [l] rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule . /index.php [l] </ifmodule> # end wordpress
it's wordpress site. strangely enough, seems it's bot blocking part being ignored. i've tried using 302 redirect , worked fine, file being read , processed.
i've noticed code seem work on sites, not others. have being addon domain? seems case code not working on primary domains either.
the .htaccess
file (together domain , wordpress installation) located in home/maindomain/addondomain
, not in home/maindomain/public_html
. there other .htaccess
files located in directories other domains host there, ones on same hierarchical level one, example:
folder1/.htaccess folder2/.htaccess thisfolder/.htaccess
but none of others have lines of code dealing bots, don't think there should interference them.
i've tried using different syntax no success, example:
rewritecond %{http_user_agent} .*dotbot.* [or] rewritecond %{http_user_agent} .*gigabot.* [or] rewritecond %{http_user_agent} .*ahrefsbot.* [or] rewriterule ^(.*)$ http://www.example.com/ [l,r=301]
another thing tried moving bot blocking parts below wordpress specific code. , tried changing placement of rewritebase /
i got reply last question saying done via robots.txt. i'd rather not though defeat purpose i'm trying achieve.
another answer received suggested removing .*
before , after botnames. names i've listed part of full name, thought i'd use these wildcards, or automatically added these commands?
do know can control of bots using robots.txt file? it's better way of instructing bots not visit parts of site, since it'll stop them attempting fetch url, don't need block either.
Comments
Post a Comment