针对任何请求显示相同的维护页面

我做了一个静态的“维护站点”页面。 我想,对于一个特定的虚拟主机,该页面显示任何URL请求。 如果我只是将vhost切换到包含页面的目录,index.html的请求将会打到页面,但是其他的会抛出404错误。

那么如何显示某个虚拟主机下的任何URL的页面呢?

RewriteEngine On RewriteCond %{REQUEST_URI} !^/index.html RewriteRule ^.*$ /index.html [L] 

完成! 每个请求将被重写为index.html。 你甚至可以[L,R=302]创build临时redirect,更好。

由于其他答案的反馈,这里是一个不被蜘蛛索引的替代scheme

 RedirectMatch 503 ^/(?!index\.html|yaml|work|css|screen) ErrorDocument 503 /index.html Header always set Retry-After "18000" 

yaml,work,css和screen是由index.html引用的目录