【问题标题】:How to correctly write .htaccess for maintenance mode?如何正确编写维护模式的 .htaccess?
【发布时间】:2013-05-03 22:30:10
【问题描述】:

我知道编写处理维护模式页面的 .htaccess 的基础知识。

我不想使用插件,因为我需要在维护模式下替换整个 WP 站点。

我已尝试添加其他规则以允许访问 WP 后端,仅适用于特定 IP。

我已经尝试了几次,最终都非常接近我的需要。

但是,我也希望列入白名单的 IP 能够看到前端站点,而不会被重定向到维护页面,但我被困在那里。

这是我当前的 .htaccess:

RewriteEngine On

RewriteCond %{REQUEST_URI} ^/images [OR]
RewriteCond %{REQUEST_URI} ^/wp-admin/.* [OR]
RewriteCond %{REQUEST_URI} ^/wp-content/.* [OR]
RewriteRule .+ - [L]

RewriteCond %{REMOTE_ADDR} !^93\.62\.93\.79
RewriteCond %{REQUEST_URI} !^/maintenance-mode\.html$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
RewriteRule .* /maintenance-mode.html [R=302,L]

我应该添加/更改什么?

【问题讨论】:

    标签: .htaccess maintenance-mode


    【解决方案1】:

    您找到解决方案了吗?我没有用 WP 对其进行测试,但这对我来说适用于另一个 CMS。

    Options +FollowSymLinks
    
    RewriteEngine On
    
    # exclude file (otherwise infinity loop)
    RewriteCond %{REQUEST_URI} !^/under-construction/maintenance\.php$
    # exclude images and css
    RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif|css) [NC]
    # If it's not your IP address
    RewriteCond %{REMOTE_HOST} !^111\.222\.333\.444$
    # Redirect /abc to example.com/abc.
    RewriteRule ^(.*)$ http://www.domain.com/under-construction/maintenance.php [R=307,L]
    

    也许对你有帮助。

    【讨论】:

    • 并非如此。当我应该离开维护模式时,我最终使用了 index.html 并重命名了它。不是一种优雅的方式,但我很着急。无论如何感谢您的帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-15
    • 2021-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多