Wordpress维护模式.htaccess

时间:2014-04-08 10:56:46

标签: wordpress .htaccess maintenance-mode

我在尝试更新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 Beginner

将顶级目录中index.php的名称更改为_index.php并将maintenance.html文件重命名为index.php是否存在任何问题?

3 个答案:

答案 0 :(得分:8)

另一种方法是使用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' ) )...

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

答案 1 :(得分: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但由于某种原因无效。

答案 2 :(得分:0)

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

如何使用此插件:

首先在WP网站上安装此插件。 安装后激活此插件。 现在点击设置,然后在“false”的地方设置“true”,您将看到您的网站自动在维护模式下运行。 您还可以从WP维护插件中的CSS样式更改维护页面样式。 enter image description here

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