2

在更新 WordPress 博客时,我尝试了多种方式来托管维护页面,但无济于事。我收到内部服务器错误。

RewriteEngine On

# Add all the IP addresses of people that are helping in development
# and need to be able to get past the maintenance mode.
# One might call this the 'allow people list'
RewriteCond %{REMOTE_HOST} !^83\.101\.79\.62
RewriteCond %{REMOTE_HOST} !^91\.181\.207\.191

# Make sure the <em>maintenance mode</em> only applies to this domain
# Example: I am hosting different sites on my server
# which could be affected by these rules.
RewriteCond %{HTTP_HOST} ^nocreativity.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.nocreativity.com$

# This is the 'ignore file list'. It allows access to all
# files that are needed to display the <em>maintenance mode</em> page.
# Example: pages, css files, js files, images, anything.
# IMPORTANT: If you don't do this properly, visitors will end up with
# endless redirect loops in their browser.
RewriteCond %{REQUEST_URI} !/offline\.htm$
RewriteCond %{REQUEST_URI} !/css\/style\.css$
RewriteCond %{REQUEST_URI} !/images\/logo\.png$

# Rewrite whatever request is coming in to the <em>maintenance mode</em> page
# The R=302 tells browsers (and search engines) that this
# redirect is only temporarily.
# L stops any other rules below this from executing whenever somebody is redirected.
RewriteRule \.*$ /offline.htm [R=302,L]

上面的代码来自No Creativity

我也试过...

# MAINTENANCE-PAGE REDIRECT
<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.000
 RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
 RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
 RewriteRule .* /maintenance.html [R=302,L]
</IfModule>

... 来自WP 初学者

只是将index.php顶级目录中的名称更改为_index.php并将我的maintenance.html文件重命名为有什么问题index.php吗?

4

3 回答 3

11

另一种方法是在你的functions.php中使用一个临时函数:

function maintenance_redirect(){
    if( !is_user_logged_in() ){
        wp_redirect( site_url( 'maintenance.html' ), 302 );
        exit();
    }
}
add_action( 'init', 'maintenance_redirect' );

这会将所有未登录的用户发送到您的维护页面,而您只要登录就可以正常使用 WordPress。如果您在网站上有注册用户,您可以将 if 语句更改为检查管理员,甚至只检查一个特定用户。

if( !is_user_logged_in() || !current_user_can( 'manage_options' ) )...

我们一直在使用它——没有插件,数据库中没有条目,并且非常快速且易于实施和删除。

于 2014-04-08T15:28:31.133 回答
2
RewriteEngine On

# Add all the IP addresses of people that are helping in development
# and need to be able to get past the maintenance mode.
# One might call this the 'allow people list'
RewriteCond %{REMOTE_HOST} !^111\.222\.333\.444

# Make sure the <em>maintenance mode</em> only applies to this domain
# Example: I am hosting different sites on my server
# which could be affected by these rules.
RewriteCond %{HTTP_HOST} ^yourdomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.yourdomain.com$

# This is the 'ignore file list'. It allows access to all
# files that are needed to display the <em>maintenance mode</em> page.
# Example: pages, css files, js files, images, anything.
# IMPORTANT: If you don't do this properly, visitors will end up with
# endless redirect loops in their browser.
RewriteCond %{REQUEST_URI} !/maintenance\.html$
RewriteCond %{REQUEST_URI} !/somejavascriptfile\.js$
RewriteCond %{REQUEST_URI} !/css\/yourstylesheet\.css$
RewriteCond %{REQUEST_URI} !/img\/yourlogo\.jpg$

# Rewrite whatever request is coming in to the <em>maintenance mode</em> page
# The R=302 tells browsers (and search engines) that this
# redirect is only temporarily.
# L stops any other rules below this from executing whenever somebody is redirected.
RewriteRule \.*$ /maintenance.html [R=302,L]

这是我使用的样本,最初来自No Creativity,但由于某种原因没有工作。

于 2014-04-11T16:03:29.367 回答
0

亲爱的迈克,为什么要修改 HTTP 访问文件,只需下载“WP 维护模式” http://wordpress.org/plugins/wp-maintenance-mode/screenshots/

如何使用这个插件:

首先在您的 WP 网站中安装此插件。安装后激活此插件。现在单击设置,然后在“false”的位置设置“true”,您将看到您的网站自动以维护模式运行。您还可以从 WP 维护插件中的 CSS 样式更改维护页面样式。 在此处输入图像描述

如果您需要任何其他帮助,我随时可以为您提供帮助

于 2014-04-08T11:43:35.703 回答