【发布时间】:2010-03-02 09:08:24
【问题描述】:
在我们安装第二台服务器时,我必须关闭一个站点大约半小时。使用 .htaccess,我如何将任何请求重定向到 domain.com 到 domain.com/holding_page.php?
【问题讨论】:
标签: .htaccess
在我们安装第二台服务器时,我必须关闭一个站点大约半小时。使用 .htaccess,我如何将任何请求重定向到 domain.com 到 domain.com/holding_page.php?
【问题讨论】:
标签: .htaccess
【讨论】:
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC] 可能是个好主意。这会阻止图像突破,将它们重定向到保留页面。我知道这严格来说不是原始问题的一部分 - 但仍然很方便。
当我遇到这个问题时,这是我使用的解决方案(cmets 中的简要说明):
RewriteEngine On
RewriteBase /
# do not redirect when using your IP if necessary
# edit to match your IP
RewriteCond %{REMOTE_ADDR} !^1\.1\.1\.1
# do not redirect certain file types if necessary
# edit to match the file types needed
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif|css)
# this holding page that will be shown while offline
RewriteCond %{REQUEST_URI} !^/offline\.html$
# use 503 redirect code during the maintenance job
RewriteRule ^(.*)$ /offline.html [R=503,L]
ErrorDocument 503 /offline.html
# bots should retry accessing your page after x seconds
# edit to match your maintenance window
Header always set Retry-After "3600"
# disable caching
Header Set Cache-Control "max-age=0, no-cache, no-store"
除了附加条件和标头之外,主要思想是在进行维护工作时使用503 状态代码。
503 代码代表Service Unavailable,在维护期间正是如此。使用它也将是 SEO 友好的,因为机器人不会索引 503 页面,它们将在指定的 Retry-After 之后返回以查找实际内容。
在此处阅读更多详细信息:
【讨论】:
这样效果更好...
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !/holding_page.php$
RewriteRule $ /holding_page.php [R=307,L]
【讨论】: