使用 htaccess 隐藏地址栏上的维护页面



如果我想将所有请求重定向到显示"维护"的单个页面,我会在htaccess中执行以下操作

RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
RewriteCond %{REQUEST_URI} !.(jpe?g?|png|gif) [NC]
RewriteRule .* /maintenance.html [R=307,L]

但是,如果我想从地址栏中的 url http://www.example.com/maintenance.html 中隐藏 /maintenance.html怎么办?

这是不可能的。
您可以使用:

RewriteCond %{REQUEST_URI} !.(jpe?g?|png|gif) [NC]
RewriteRule !^maintenance.html$ /maintenance.html [NC,L]

但在这种情况下,没有错误代码或重定向。
如果要重定向,地址栏中的 url 必然会发生变化。

最新更新