php 当站点因维护而关闭时要发送的正确 HTTP 状态代码是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/2786595/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the correct HTTP status code to send when a site is down for maintenance?
提问by alex
Is there a HTTP status code to tell Google (and others) to go away, index me again later?
是否有 HTTP 状态代码告诉 Google(和其他人)离开,稍后再次索引我?
Basically, one that semantically tells clients that the site is down for maintenance?
基本上,一种从语义上告诉客户该站点已关闭以进行维护的程序?
The ones I have considered are
我考虑过的有
304 => Not modified
307 => Temporary redirect
410 => Gone
503 => Service Unavailable
I'm leaning towards the last one, but was just curious as to which one was properchoice.
我倾向于最后一个,但只是好奇哪一个是正确的选择。
回答by Daniel Vassallo
HTTP 503 - Service Unavailablewould be the most appropriate.
HTTP 503 - 服务不可用将是最合适的。
The Web server (running the Web site) is currently unable to handle the HTTP request due to a temporary overloading or maintenance of the server. The implication is that this is a temporary condition which will be alleviated after some delay.
由于服务器临时过载或维护,Web 服务器(运行网站)当前无法处理 HTTP 请求。这意味着这是一个暂时的情况,将在一些延迟后得到缓解。
This post on the Google Webmaster Central Forum is also relevant:
Google 网站管理员中心论坛上的这篇文章也很相关:
Yes - a 503 is the correct server response for "We're closed". If you substitute a normal HTML page saying "We're closed" and serve a 200 it's very likely to get indexed by Google.
If you give the Googlebot a 503, it will just go away and come back later without indexing what you give it.
是的 - 503 是“我们已关闭”的正确服务器响应。如果您替换一个普通的 HTML 页面,上面写着“我们已关闭”并提供 200 个页面,则很可能会被 Google 编入索引。
如果您给 Googlebot 一个 503,它就会消失并稍后返回,而不会索引您给它的内容。
UPDATE:
更新:
As for the php implementation, you may be interested in checking out the following article:
至于php的实现,你可能有兴趣查看以下文章:
Also notice the retry-afterheader, where you can specify after how many seconds another request should be re-attempted.
还要注意retry-after标题,您可以在其中指定应重新尝试多少秒后的另一个请求。
回答by Lee
From http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=40132
来自http://www.google.com/support/webmasters/bin/answer.py?hl=zh-CN&answer=40132
503 (Service unavailable) The server is currently unavailable (because it is overloaded or down for maintenance). Generally, this is a temporary state.
503(服务不可用)服务器当前不可用(因为它过载或停机维护)。通常,这是一种临时状态。
回答by Ham Vocke
I'd consider the 503 to be most appropriate, since the 5xx-group is meant for server errors in general.
我认为 503 是最合适的,因为 5xx-group 通常用于处理服务器错误。
回答by dan04
503 Service Unavailable
503服务不可用

