I have a Yii 1.x application, that contains a frontend and a backend, split into modules. In current state, all not matching routes are not handled and causes an error. My urlManager is configured to use "pretty" URLs:
'urlManager'=>array
(
'class'=>'UrlManager',
'showScriptName'=>false,
'urlFormat'=>'path',
'rules'=>array
(
...
)
)
I want to have my existing urlManager’s rules to be handled without change, but I want all other, not matching routes to be routed to application’s router (that’s why I can use catchAllRequest).
Here are my attempts to solve this problem, that I tried so far and that have failed:
Putting (.*) to rules (from harrybailey.com blog and this answer) – no change at all:
- frontend requests handled normally (OK),
- backend requests handled normally (OK),
- invalid requests causes an error (wrong).
Porting Yii2 solution from this answer:
- frontend requests handled normally (OK),
- backend requests routed (wrong),
- invalid requests routed (OK).
To summarize, I don’t know:
[list=1][]Why first solution isn’t working at all (for me it looks like no change), even though many sources claims, this should work?[]Why second solution ignores my defined rules only for backend. This is the biggest surprise – how can frontend routes work and backend (module-based) routes to be routed as well as invalid, not matching routes?[*]Which solution to use, that will work as expected?[/list]
This answer (though to Yii2) gave me some idea, so I ported this solution to Yii1, and used it as workaround, by putting this line:
if($error['code'] === 404 && $error['type'] === 'CHttpException') $this->forward('application/route');
to standard Yii’s actionError’s code. It works like a charm, but I don’t think this is best option. And I’d like to know, why other solutions, mentioned above, does not work?