Routing Specifics

I have the following controller “AjaxController” with the following action “actionRoleUsers”. I don’t understand why when I set this rule




[

'pattern'=>'ajax/<action:\w+>/<id>',

'route' => '<controller>/<action>',

'defaults' => ['id' => ""],                   

],



and try to consume the url ajax/role-users/1 a 404 error is thrown as opposed to setting this rule the action is carried out successfully. I am trying not to set the specific rule for every action which will be set in the mentioned controller




[

'pattern'=>'<controller:(ajax)>/role-users/<id>',

'route' => 'ajax/role-users',

'defaults' => ['id' => ""],                   

], 



I had the exact same issue when using defaults, I couldn’t get it to work, you could add 2 rules as follows instead of 1 (I know you are trying to avoid this)




'ajax/<action:\w+>' => '<controller>/<action>'

'ajax/<action:\w+>/<id>' => '<controller>/<action>/'



PS. If you figure out how to make it work "the right way" please do post your solution back here