就我个人而言,我是通过 IP 来做的——所以我可以让我的网站离线,但我仍然可以完全访问它(测试新功能并确保它在恢复之前工作)
RewriteEngine on
# For maintenance:
# If your IP address is 1.1.1.1 - then dont re-write
RewriteCond %{REMOTE_ADDR} !^1\.1\.1\.1
# If the person is requesting the maintenance page, also dont rewrite (prevent loops)
RewriteCond %{REQUEST_URI} !/maintenance.html$
# Otherwise rewrite all requests to the maintenance page
RewriteRule $ /maintenance.html [R=302,L]
# do not rewrite links to the documentation, assets and public files
RewriteCond $1 !^(assets)
# do not rewrite for php files in the document root, robots.txt or the maintenance page
RewriteCond $1 !^([^\..]+\.php|robots\.txt|maintenance\.html)
# but rewrite everything else
RewriteRule ^(.*)$ index.php/$1 [L]
只需将 !^1.1.1.1 更改为您当前的 IP。即!^121.65.56.65
如果您不确定您的 IP 是什么 - 只需谷歌“我的 IP 是什么” - 它会显示为第一次点击
但就您的具体问题而言 - 这应该有效:
RewriteCond %{REQUEST_URI} !/admin$
RewriteRule $ /index_failsafe.php [R=302,L]
编辑: