views:

45

answers:

2

I put an .htaccess file in my webroot with the following contents

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

This website is in maintenance mode, and I don't want anything indexed yet. I tested the code with a firefox User-Agent switcher plugin, and looking at the access log it shows this at the end of each log entry, but watching in TamperData or Firebug, it still returns a 200 server response instead of a 503. What am I doing wrong?

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

contents of /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::: Added small snippet from the rewrite.log Here is a small sample, I went thru the entire log, and everything is referring to a javscript or image file:

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
+1  A: 

Either use:

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

Or when you're not on Apache 2.x yet where the above construct is supported, then make it a 503.php page and set in top of code:

header("HTTP/1.1 503 Service Temporarily Unavailable"); 
BalusC
+1  A: 

You have an infinite loop. The result of your rewrite is being rewritten again.

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

As @BalusC pointed out, you also need the R flag.

Artefacto
I changed the .htaccess file to exactly what you put above. I am not receiving an error anymore, but it's not loading my 503.html file, it's loading the 503 coming soon. And the user agent in the apache log still says Googlebot.
Hallik
@Hallik Post your rewritelog with rewriteloglevel 9.
Artefacto
I have updated the original post to include the relevant line in the rewrite.log. I verified in the access_log it shows Googlebot as the useragent.
Hallik
@Hallik The IP is of a reserved private range. Are you sure it was the Google bot?...
Artefacto
I am testing this locally using a UserAgent Switcher in firefox to mimic the Googlebot
Hallik
@Hallik well, your log entry suggests `%{HTTP_USER_AGENT}` is expanding to nothing. No idea why that might be happening.
Artefacto