更新
自Yii 1.1.16起,旧代码示例停止工作.感谢JamesG(见评论)的新解决方案.代码示例已更新.
正如您已经想到的那样,catchAllRequest是从yii中执行此操作的最佳方法.它是专门针对此类情况而制作的,正如文档中非常明显的那样.使用它也可能会使你的性能略有提高(超过urlManager),但我怀疑它会引人注意.
另一方面,如果您想使用urlManager,可以尝试(也可以阅读代码示例中的注释):
1.1.16及以上版本:
'<url:(.*)>'=>'maintenance/index'
Run Code Online (Sandbox Code Playgroud)1.1.15及以下版本:
'<url:(.*)>'=>'maintenance/index'
// '(.*)'=>'maintenance/index' // this used to work in previous versions ...
// of Yii (below 1.1.16) mainly due to a bug, see notes
Run Code Online (Sandbox Code Playgroud)注意:这必须是urlManager rules阵列配置中的第一条规则.
然而正如sl4mmer已经提到的,htaccess或服务器配置是最好的方法,因为服务器毕竟在将请求发送到php之前首先捕获请求.
注意Bug:在这里检查github问题.