通过修改htaccess的阻止机器人 [英] Blocking bots by modifying htaccess

查看:191
本文介绍了通过修改htaccess的阻止机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图阻止通过我的htaccess文件一对夫妇的机器人。在搜索引擎观察,建议使用如下。我没有阻止这些机器人在robots.txt文件,但他们忽略了它。

下面是从搜索引擎观察code:

  RewriteEngine叙述上
选项​​+的FollowSymLinks
的RewriteBase /
的RewriteCond%{HTTP_USER_AGENT} ^ Baiduspider [NC,OR
的RewriteCond%{HTTP_USER_AGENT} ^搜狗
。重写规则^ * $  -  [F
 

我目前htaccess文件是如下。究竟如何,我会改变我目前的.htaccess上述code?我怎么添加和我在哪里添加上面?我认为上述的一些已经包括在我目前htaccess的文件,并不需要重复。

下面是我当前的.htaccess:

 #BEGIN字preSS
    < IfModule mod_rewrite.c>
    RewriteEngine叙述上
    的RewriteBase /
    重写规则^指数\ .PHP $  -  [L]
    的RewriteCond%{} REQUEST_FILENAME!-f
    的RewriteCond%{} REQUEST_FILENAME!-d
    重写规则。的index.php [L]
    < / IfModule>

   #结束字preSS
 

解决方案

删除选项线,只需添加它们上面的字preSS规则,也改变在]

  RewriteEngine叙述上
的RewriteCond%{HTTP_USER_AGENT} ^ Baiduspider [NC,OR]
的RewriteCond%{HTTP_USER_AGENT} ^搜狗[NC]
。重写规则^ * $  -  [F]

#BEGIN字preSS
< IfModule mod_rewrite.c>
RewriteEngine叙述上
的RewriteBase /
重写规则^指数\ .PHP $  -  [L]
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则。的index.php [L]
< / IfModule>

#结束字preSS
 

如果您有其他的用户代理要阻止,只是添加高于目前的那些多个条件:

 的RewriteCond%{HTTP_USER_AGENT} ^不旺,这串[NC,OR]
 

I am trying to block a couple bots via my htaccess file. On Search Engine Watch it is recommended to use the below. I did block these bots in the robots.txt file but they are ignoring it.

Here is code from Search Engine Watch:

RewriteEngine on 
Options +FollowSymlinks 
RewriteBase / 
RewriteCond %{HTTP_USER_AGENT} ^Baiduspider [NC,OR" 
RewriteCond %{HTTP_USER_AGENT} ^Sogou
RewriteRule ^.*$ - [F"

My current htaccess file is as below. How exactly would I modify my current .htaccess with the above code? What do I add and where do I add the above? I assume some of the above is already included in my current htaccess file and does not need to be repeated.

Here is my current .htaccess:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

   # END WordPress

解决方案

Remove the Options line and just add them above your wordpress rules, and also change the " to ]:

RewriteEngine on 
RewriteCond %{HTTP_USER_AGENT} ^Baiduspider [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Sogou [NC]
RewriteRule ^.*$ - [F]

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

If you have other user agents you want to block, just add more conditions above the current ones:

RewriteCond %{HTTP_USER_AGENT} ^dont-want-this-string [NC,OR]

这篇关于通过修改htaccess的阻止机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆