1

我试图只向除选择 IP 之外的所有人显示即将推出或维护页面。我现在尝试了几种解决方案并确定了此代码

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^xx\.xx\.xx\.xx
RewriteCond %{REQUEST_URI} !/coming-soon\.html$
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif|css|js|woff) [NC]
RewriteRule .* /coming-soon.html [R=302,L]
</IfModule>

每当有人访问主页时,这都非常有用。但是,如果您转到任何其他页面,例如 /contact、/shop、.etc,它不会重定向。

我已将此代码放在页面底部。当我尝试将其移动到页面顶部时,我收到一条错误消息,指出许多重定向。下面是我的标准 Wordpress 重定向。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

如何将所有页面限制为除选择 ip 之外的所有页面?

谢谢

编辑 我已经在没有缓存插件或将代码添加到 htaccess 的安全插件的新服务器上进行了测试,但我仍然遇到同样的问题。对主页的请求会被重定向,但对任何其他页面的请求不会。下面是我的 htaccess 文件中的代码。

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

# BEGIN Trusted Access
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^xx\.xx\.xxx\.x
RewriteCond %{REQUEST_URI} !/coming-soon\.html$
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif|css|js|woff) [NC]
RewriteRule ^(.*)$ /coming-soon.html [R=302,L]
</IfModule>
# END Trusted Access
4

2 回答 2

0

方法 #1:自定义代码以显示维护页面

如果你想在你的站点上显示一个基本的维护启动页面而不使用维护模式插件,你可以将这段代码添加到你的 functions.php

function wp_maintenance_mode() {
   if (!current_user_can('edit_themes') || !is_user_logged_in()) {
     wp_die('<h1>Under Maintenance</h1><br />Something ain't right, but we're working on it! Check back later.');
   }
}
add_action('get_header', 'wp_maintenance_mode');

方法 #2:通过 .htaccess 文件启用维护模式

对于这种方法,必须具有编辑服务器上的 .htaccess 文件的权限。该文件可以在您网站的根目录中找到。打开此文件后,复制并粘贴以下代码:

RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} !^111\.111\.111\.111
RewriteCond %{REQUEST_URI} !^/maintenance\.html$
RewriteRule ^(.*)$ https://example.com/maintenance.html [R=307,L]

方法#3:使用 WordPress 维护模式插件

于 2019-12-10T05:37:29.153 回答
0

嗨,保罗

我根据问题尝试了一些解决方案,即使用任何插件进行维护模式的最佳方式(例如 wp 维护模式)

或试试这个

  • 您必须在根目录中创建一个 maintenance.html 文件,其中包含您想要显示给用户的任何消息。
  • 您也可以在 RewriteCond %{REMOTE_ADDR} 中设置 ip 以设置允许的 ip 地址

维护页面重定向

<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteCond %{REMOTE_ADDR} !^192\.168\.0\.62
 RewriteCond %{REQUEST_URI} !http://192.168.0.254/html/woocommerce-task/maintenance.html$ [NC]
 RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
 RewriteRule .* http://192.168.0.254/html/woocommerce-task/maintenance.html [R=302,L]
</IfModule>
  • 如果只想允许一些 ip
<Limit GET POST>
    Order Deny,Allow
    Deny from all
    Allow from 192.168.0.254
</Limit>

Note:- Change the ip address with ones that you want to allow and remember to use static ip for development. so it will be easy for you to restrict access for the site.
于 2019-12-10T07:46:56.323 回答