针对Googlebot的503服务器响应

时间:2010-06-15 17:56:01

标签: apache mod-rewrite

我在我的webroot中放了一个.htaccess文件,其中包含以下内容

RewriteBase /
RewriteCond %{HTTP_USER_AGENT} ^.*(Googlebot|Googlebot|Mediapartners|Adsbot|Feedfetcher)-?(Google|Image)? [NC]
RewriteRule .* /var/www/503.html

这个网站处于维护模式,我不想要任何索引。我使用firefox User-Agent切换器插件测试了代码,并查看了在每个日志条目末尾显示的访问日志,但是在TamperData或Firebug中观看,它仍然返回200服务器响应而不是503。我做错了吗?

"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"

/var/www/503.html

的内容
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>503 - Service temporary unavailable</title>
</head>
<body>
<h1>503 - Service temporary unavailable</h1>
<p>Sorry, this website is currently down for maintainance please
retry later</p>
</body>
</html>

::: EDIT ::: 从rewrite.log中添加了小片段     这是一个小样本,我通过整个日志,一切都是指javascript或图像文件:

172.16.173.26 - - [15/Jun/2010:15:03:31 --0500] [qa-test.com/sid#2b6c1c8ba938][rid#2b6c24cfdd18/initial] (4) [perdir /var/www/qa-test.com/web/] RewriteCond: input='' pattern='^.*(Googlebot|Googlebot|Mediapartners|Adsbot|Feedfetcher)-?(Google|Image)?' [NC] => not-matched

2 个答案:

答案 0 :(得分:1)

使用:

RewriteRule .* /var/www/503.html [R=503,L]

或者当你不在支持上述结构的Apache 2.x上时,请将其设为503.php页并设置在代码顶部:

header("HTTP/1.1 503 Service Temporarily Unavailable"); 

答案 1 :(得分:1)

你有一个无限循环。重写的结果将被重写。

RewriteBase /
RewriteCond %{HTTP_USER_AGENT} (?:Googlebot|Googlebot|Mediapartners|Adsbot|Feedfetcher)-?(?:Google|Image)? [NC]
RewriteCond $0 !(?:^|/)503\.html$
RewriteRule .* /var/www/503.html [R=503]

正如@BalusC指出的那样,你还需要R标志。