apache 重写“站点关闭”页面的规则
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1337837/
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
Rewrite rule for "site down" pages
提问by Paul Tarjan
I was trying to install this .htaccess to notify my users of site maintenance. It seems the first [L] isn't working and the second rewrite is doing everything.
我试图安装这个 .htaccess 来通知我的用户站点维护。似乎第一个 [L] 不起作用,第二个重写正在做所有事情。
How do you guys do site maintenance messages?
你们怎么做网站维护消息?
RewriteEngine on
RewriteRule ^s/down$ index.html [L]
RewriteRule ^(.*)$ http://metaward.com/s/down [R=302,L]
回答by Gumbo
You don't need to an external redirect. Just send the 503 status codeand your error document.
您不需要外部重定向。只需发送503 状态代码和您的错误文档。
RewriteCond %{ENV:REDIRECT_STATUS} !=503
RewriteRule ^(.*)$ /503.html [R=503,L]
ErrorDocument 503 /503.html
But you need Apache 2.x to use a different status code with the R flag other than 3xx.
但是您需要 Apache 2.x 才能使用带有 R 标志而不是 3xx 的不同状态代码。
回答by Paul Tarjan
This seems to work (but I have to set the status code in PHP)
这似乎有效(但我必须在 PHP 中设置状态代码)
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/static/.*$
RewriteCond %{REQUEST_URI} !^/media/.*$
RewriteRule .* down.php [L]
and in down.php
并在 down.php
<?php
header('HTTP/1.1 503 Service Temporarily Unavailable',true,503);
?>
Any problems with this? My main concerns are what user's see (which is why i keep static content) and what search engines see (the 503 status code).
这有什么问题吗?我主要关心的是用户看到的内容(这就是我保留静态内容的原因)和搜索引擎看到的内容(503 状态代码)。
回答by Pascal MARTIN
The RewriteRules I'm using on my website when I want to shut it down for maintenance are these ones :
当我想关闭网站进行维护时,我在我的网站上使用的 RewriteRules 是这些:
RewriteCond %{REMOTE_ADDR} !=MY_IP_ADDRESS
RewriteRule ^$ /down.html [L]
RewriteCond %{REMOTE_ADDR} !=MY_IP_ADDRESS
RewriteRule [^/down.html$] /down.html [L]
(Maybe not quite "optimized", I should say... But it worked (or so it seemed) each time I used those)
(也许不是很“优化”,我应该说......但每次我使用它们时它都有效(或者看起来如此))
Everything but down.html gets redirected to down.html -- except for me, of course : I want to be able to test the maintenance operations I'm doing, obviously
除了 down.html 之外的所有内容都被重定向到 down.html——当然,除了我:我希望能够测试我正在做的维护操作,显然
ANd when I'm finished, I just comment those four lines.
并且当我完成时,我只是评论这四行。
回答by Nino van Hooff
I use Apache as a proxy for a ruby on rails application.
我使用 Apache 作为 ruby on rails 应用程序的代理。
The only thing I had to do was add
我唯一要做的就是添加
ProxyPass /custom-errors !
ErrorDocument 503 /custom-errors/maintenance-message.html
To my httpd.conf and make sure that : [Apache installation]/htdocs/custom-errors/maintenance-message.html exists.
到我的 httpd.conf 并确保:[Apache 安装]/htdocs/custom-errors/maintenance-message.html 存在。
回答by Tom
I don't see anyone using the Retry-After header. I've read (but don't have the link anymore as I read it a while ago) that you should use a 503 in combo with a Retry-After n (n = number of seconds to try again in; 3600 is an hour) header. If you use the 503 and the Retry-After in combo, especially on your robots.txt/sitemap it should not mess with links and page rank for SEO if you don't leave it like that for a long time.
我没有看到任何人使用 Retry-After 标头。我已经读过(但我之前读过它时不再有链接了)你应该将 503 与 Retry-After n 组合使用(n = 重试的秒数;3600 是一个小时) 标题。如果您在组合中使用 503 和 Retry-After,尤其是在您的 robots.txt/sitemap 上,如果您长时间不这样做,它不应该混淆 SEO 的链接和页面排名。

