僵尸阻挡code忽略htaccess的?僵尸、code、htaccess

2023-09-02 00:37:07 作者:*祸}暮~l}俚

我一直在努力,现在解决这个好几天了,却找不到答案。在我使用一个共享的托管帐户,我想修改的.htaccess 文件从访问网站阻止某些机器人。这是code我用:

I've been trying to solve this for several days now, but can't find an answer. On a shared hosting account I'm using, I'd like to modify the .htaccess file to block certain bots from visiting the site. This is the 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 GET POST HEAD>
Order Allow,Deny
Allow from all
Deny from env=bad_bot
</Limit>
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

这是一个字preSS网站。奇怪的是,似乎就这么被忽略只僵尸阻挡一部分。我已经使用302重定向尝试,它能正常工作,因此该文件被读取并处理。

It's a WordPress site. Strangely enough, it seems that it's just the bot blocking part that is being ignored. I've tried using a 302 redirect and it worked fine, so the file is being read and processed.

我也注意到,这code似乎工作在一些网站,但不是为别人。难道有什么做这个作为一个附加域?然而,似乎是code不工作的一些主要领域,无论是案例。

I've also noticed that this code does seem to work on some sites, but not for others. Could it have something to do with this being an addon domain? However it seems to be the case that the code is not working on some primary domains either.

的.htaccess 文件(域和词preSS安装在一起)位于家用/ maindomain / addondomain 而不是家用/ maindomain /的public_html 。有位于目录中的其他领域我是主持人没有其他的的.htaccess 文件,但只有那些在同一层级这一个,因此,例如:

The .htaccess file (together with the domain and wordpress installation) is located in home/maindomain/addondomain and not in home/maindomain/public_html. There are other .htaccess files located in directories for the other domains I host there, but only ones that are on the same hierarchical level as this one, so for example:

folder1/.htaccess

folder2/.htaccess

thisfolder/.htaccess

但没有其他人有code处理机器人的任何行,所以我不认为应该从他们的任何干扰。

But none of the others have any lines of code dealing with bots, so I don't think there should be any interference from them.

我也试着使用不同的语法没有成功,例如:

I've also tried using different syntax with no success, for 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]

另一件事情我想是移动机器人阻挡低于字preSS具体code部位。我也试图改变位置的RewriteBase /

我有我的最后一个问题答复说,它可以通过robots.txt的实现。我宁愿不这样做,但因为它会破坏目的我想实现的。

I got a reply to my last question saying that it could be done via robots.txt. I'd rather not do that though as it would defeat the purpose I'm trying to achieve.

我收到了另一个答案建议删除。* 前后botnames。我列出的名称是全名的一部分,所以我想我会用这些通配符,或者他们得到这些命令会自动添加?

Another answer I received suggested removing the .* before and after botnames. The names I've listed are only part of the full name, so I thought I'd use these wildcards, or do they get automatically added with these commands?

推荐答案

你知不知道,你可以使用的的robots.txt文件?这是指导这些机器人不会访问您的网站的某些部分,因为它会从甚至试图获取一个URL阻止他们的一个更好的方法,让你不必为阻止它。

Do you know you can control most of those bots using a robots.txt file? It's a much better way of instructing those bots not to visit certain parts of your site, since it'll stop them from even attempting to fetch a URL, so you don't need to block it either.