如何修改503 htaccess规则以避免Googlebot无法访问您的网站'错误?

时间:2014-06-17 16:57:56

标签: php regex .htaccess mod-rewrite http-status-code-503

我要求一个网站在建设中返回503。

我正在把游客指向友好的“即将推出”#39;页面,但Google网站站长工具报告" Googlebot无法访问您的网站"。

这是.htaccess中的当前规则:

<IfModule mod_rewrite.c>
RewriteEngine On

# Allow Access Locally
RewriteCond %{REMOTE_ADDR} !^127.0.0.1

# Prevent 503 for Maintenance Page
RewriteCond %{REQUEST_URI} !/maintenance [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]

# Show Friendly 503
RewriteRule .* http://www.example.com/maintenance/index.php [R=503,L]
</IfModule>

它适用于访问者,但我如何修改规则以确保Google了解503?

在维护文件的标题中,我有:

<?php
header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');
header('Retry-After: Wed, 18 Jun 2014 01:00:00 GMT');
?>

我认为Google正试图访问robots.txt。这应该从503指令中排除吗?

谢谢

1 个答案:

答案 0 :(得分:1)

替换此行:

RewriteRule .* http://www.example.com/maintenance/index.php [R=503,L]

使用:

RewriteRule !^503\.php$ /503.php [L,NC]

/503.php内添加http_response_code(503),如下所示:

<?php
http_response_code(503);
header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');
header('Retry-After: Wed, 18 Jun 2014 01:00:00 GMT');
?>