我试图只向除选择 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