Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
重写条件-错误标志分隔符.htaccess(Apache)_Apache_.htaccess_Mod Rewrite_Delimiter - Fatal编程技术网

重写条件-错误标志分隔符.htaccess(Apache)

重写条件-错误标志分隔符.htaccess(Apache),apache,.htaccess,mod-rewrite,delimiter,Apache,.htaccess,Mod Rewrite,Delimiter,我正在尝试使用.htaccess将bot/不需要的客户端重定向到错误页面。 但在任何连接上,它只会带来“RewriteCond:Bad flag delimiters” .htaccess: RewriteEngine On Options +FollowSymlinks RewriteBase / RewriteCond %{HTTP_USER_AGENT} askpeter_bot [NC,OR] RewriteCond %{HTTP_USER_AGENT} Jakarta [NC,OR]

我正在尝试使用.htaccess将bot/不需要的客户端重定向到错误页面。 但在任何连接上,它只会带来“RewriteCond:Bad flag delimiters”

.htaccess:

RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} askpeter_bot [NC,OR]
RewriteCond %{HTTP_USER_AGENT} Jakarta [NC,OR]
...
RewriteCond %{HTTP_USER_AGENT} Genieo [NC]
RewriteRule ^(.*) "http\:\/\/www\.example\.com\/bots\/notallowed.html" [F]
你知道有什么问题吗?


编辑:
现在我使用deny来阻止用户代理

deny from env=block
SetEnvIfNoCase User-Agent "USER-AGENT" block=yes

但这不是我想要的方式,因为您只得到一个空页面,没有消息。为什么当您使用[F]或[R=403]标志时,apache会为指定的代码呈现。您可以使用ErrorDocument指令如下设置:

ErrorDocument 403 /bots/notallowed.html
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} askpeter_bot [NC,OR]
RewriteCond %{HTTP_USER_AGENT} Jakarta [NC,OR]
RewriteCond %{HTTP_USER_AGENT} Genieo [NC]
RewriteRule ^(.*)$ /bots/notallowed.php [L]
在您的案例中,这种方法的问题是,当发送403代码时,它将用于机器人和人类

为了将此限制在机器人上,我建议如下:

ErrorDocument 403 /bots/notallowed.html
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} askpeter_bot [NC,OR]
RewriteCond %{HTTP_USER_AGENT} Jakarta [NC,OR]
RewriteCond %{HTTP_USER_AGENT} Genieo [NC]
RewriteRule ^(.*)$ /bots/notallowed.php [L]
然后在notallowed.php中,您可以使用header函数发送正确的header:

<?php header("HTTP/1.0 403 Forbidden"); ?>
Go away, bot.
如果出于某种原因,这不起作用,请尝试以下python:

python -c "f = open('.htaccess', 'r'); f.seek(0); file = f.readlines(); print file"

尝试此
重写规则。*http://www.example.com/bots/notallowed.html [R=403,L]
试过了。同样的ErrorMessage已经尝试过了,这是同样的问题->“坏的标志分隔符”奇怪,我在发布之前测试过,它工作正常。您的.htaccess中有其他规则吗?如果你把这条规则之外的所有东西都注释掉,会发生什么?你使用的是什么版本的Apache?里面有更多的机器人用户代理(都是和我问题中的一样的格式),但没有别的。我正在使用apache/2.2.16(Debian)。(是的,已加载mod_rewrite)无需担心。。。我很傻。。。我只是再次搜索了.htaccess,看到一个未被替换的空间字符。。。现在它开始工作了