Wordpress维护模式.htaccess

Mik*_*ike 2 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]
Run Code Online (Sandbox Code Playgroud)

上面的代码来自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>
Run Code Online (Sandbox Code Playgroud)

......来自WP初学者

只是将index.php顶层目录中的名称更改为_index.php并将我的maintenance.html文件重命名为index.php

I'm*_*Too 8

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

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

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

if( !is_user_logged_in() || !current_user_can( 'manage_options' ) )...
Run Code Online (Sandbox Code Playgroud)

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