WordPress维护模式.htaccess

标签 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?

最佳答案

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

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

关于WordPress维护模式.htaccess,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22934885/

相关文章:

css - 托管服务是否可能不支持 CSS 中的媒体查询?

.htaccess - 从 URL 中删除目录

.htaccess - htaccess 重定向性能

unit-testing - 维护阶段的单元测试

api - 如何为 Heroku API 实现维护模式

wordpress - PHPStorm 和 WordPress 项目错误

php - 由于 WordPress 无法访问我的文件夹

wordpress - 被黑的 WordPress - 如何摆脱 "casino ..."

php - 使用PHP和htaccess处理错误页面

php - 在线开发网站时,如何让别人无法访问网站?