Update
The old code sample stopped working since Yii 1.1.16. Thanks to JamesG (see comment) for the new solution. Code sample has been updated.
As you have already figured out, catchAllRequest
is the best way to do this from within yii. It has been made specifically for such cases, as is quite evident from the documentation. Using it could also probably give you a slight performance increase (over urlManager
), but i doubt that it'll be noticeable.
On the other hand if you wish to use urlManager
, you can try with (also read comments in code sample):
Version 1.1.16 and above:
'<url:(.*)>'=>'maintenance/index'
Version 1.1.15 and below:
'<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
Note: This will have to be the first rule in your urlManager's rules
array configuration.
However as already mentioned by sl4mmer, htaccess or server configuration is the best way to do this, since the server after all catches the request first before sending it to php.
Note for Bug:
Check github issue here.