Answer the question
In order to leave comments, you need to log in
How to block User-Agent requests via .htaccess?
Hello! Placed in .htaccess rules blocking requests from certain User-Agents. The multi-line construction (bottom) works, but the abbreviated one containing regular expressions does not work, i.e. causes a 404 error for any User-Agent. What could be the reason?
#Эта конструкция не работает - вызывает ошибку 404, когда заходишь на сайт для всех User-Agent.
RewriteCond %{HTTP_USER_AGENT} [SolomonoBot|HaosouSpider|MJ12Bot|AhrefsBot|SemrushBot|360Spider]
RewriteRule ^.*$ - [R=404,L]
#А эта конструкция работает, но она слишком большая. Что я делаю не так?
RewriteCond %{HTTP_USER_AGENT} HaosouSpider [NC,OR]
RewriteCond %{HTTP_USER_AGENT} MJ12bot [NC,OR]
RewriteCond %{HTTP_USER_AGENT} AhrefsBot [NC,OR]
RewriteCond %{HTTP_USER_AGENT} SemrushBot
RewriteCond %{HTTP_USER_AGENT} 360Spider [NC,OR]
RewriteRule .* - [R=404,L]
#Вот так всё работает
RewriteCond %{HTTP_USER_AGENT} (SolomonoBot|HaosouSpider|MJ12Bot|AhrefsBot|SemrushBot|360Spider)
RewriteRule ^.*$ - [R=404,L]
Answer the question
In order to leave comments, you need to log in
SetEnvIfNoCase User-Agent "ahrefs.com" bad_bot
SetEnvIfNoCase User-Agent "megaindex.ru" bad_bot
SetEnvIfNoCase User-Agent "Java/1." bad_bot
SetEnvIfNoCase User-Agent "linkpad.ru" bad_bot
<Limit GET POST HEAD>
Order Allow,Deny
Allow from all
Deny from env=bad_bot
</Limit>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question