PHP实现Down for Maintenance页面

时间:2015-04-24 14:21:30

标签: php .htaccess maintenance

我想为我的网站实现Down for Maintenance功能,但似乎我遇到了一些麻烦。让我解释一下。

我的网站结构如下所示:

websitename
     model
     view
     controller
     public
          css
          .htaccess
          index.php
     .htaccess
     index.php
     maintenance.php

我正在使用此htaccess代码将用户重定向到维护页面。 .htaccess文件代码位于公用文件夹中。

<IfModule mod_rewrite.c>
    RewriteEngine On

    #handle the redirect to maintenance
    RewriteCond %{REMOTE_ADDR} !^111\.111\.111\.111
    RewriteCond %{REQUEST_URI} !/maintenance.php$ [NC]
    RewriteRule .* /maintenance.php [R=302,L]


    # handle home page
    RewriteRule ^/?$ home [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    # Rewrite all other URLs to index.php/URL
    # RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

这似乎并没有起作用。我找了很多教程,但似乎都没有。另外,我想知道,如果用户被重定向到维护页面;维护结束后,如何将它们重定向到普通网站。

提前致谢

4 个答案:

答案 0 :(得分:1)

如果是我,我会用你的配置值创建一个配置目录。其中之一就是

$config['maintenance'] = false;
$config['maintenance_url'] = '/maintenance/';

当您想要进入维护模式时,您只需更新配置文件维护值

$config['maintenance'] = true;

并在您的前端控制器或索引文件中进行检查

if($config['maintenance'])
{
    header('Location: ' . $config['maintenance_url'] );
    // in the event page cannot redirect
    die('Under maintenance, please come back later');
}

答案 1 :(得分:0)

忽略application = processChildren $ getChildren -- Gets the children of "pous" >>> filterA hasSFC where hasSFC = hasName "pou" -- Include all "pou" elements >>> getChildren -- that have children >>> getChildren -- that have children >>> hasName "SFC" -- that have a "SFC" element main = do runX $ readDocument [] "input.xml" >>> application >>> writeDocument [withIndent yes] "output.xml" 文件并将代码直接移至.htaccess

index.php

您可以通过在根目录中创建空文件if(file_exists('maintenance.flag')){ // code to render maintenance page exit; } 来启用/禁用维护模式。

答案 2 :(得分:0)

由于php标记,我来到这里。 ¿你有没有考虑过只通过php做这件事?

我要做的是在我的php代码上有一个配置文件(或数据库)和if句子,如:

if($config['maintenance']==true) {
    include_once "maintenance.php";
} else {
    // the rest of your index.php
}

答案 3 :(得分:0)

RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
RewriteRule ^(.*)$ maintenance.html [R=302,L]

将文件名更改为您想要的文件名,您可以通过在该名称之间重命名文件来打开和关闭该网站,例如: maintenance.html将网站设为离线状态,maintenance.html.bak将网站重新设置为在线状态。