I would like have all routes except the api routes to navigate to the site/index route but all /api path to be executed to the respective modules. I have added the following route rules
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
//api module
'api/<controller:\w+>/<action:[\w\-]+>' => '<controller>/<action>',
'api/<controller:\w+>' => 'api/<controller>',
//all other paths
'<controller:[\w\-]+>/<action:[\w\-]+>' => 'site/index',
'<controller:[\w\-]+>/' => 'site/index',
],
],
The following works for 2 level url routes that is
/users/create
/users/view
But when i access routes with more than 2 paths like
/users/create/12
/admin/uom/create/new
The routes are not redirrected to site/index
What else do i need to add to ensure that all routes even with more than 3 paths are executed via site/index but those with api prefix are executed via controller/action or /api/controller.
What am i missing out?
There is no built-in support for such case. But you can create custom URL rule which will match any route:
And use it in your app config:
Note that it will simply ignore request path and catch all requests, including these that should throw 404 error. It will also not detect parameters in path (it will ignore
12in/users/create/12).