Reputation: 23
i use below code for url manager in Yii2 Framework :
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
'<module:\w+>/<action:\w+>' => '<module>/default/<action>'
]
],
but. when enable the rule that remove default from url for modules , the rule for controllers stops working.
where the problem is my code?
thanks.
Upvotes: 0
Views: 1237
Reputation: 818
The problem is - your module rule overriders controller one.
The <module>
and <controller>
are not a keywords for UrlManager, so - in your case it does not works.
Your Url-config should be like that:
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
'<module:\w+>/<controller:\w+><action:\w+>' => '<module>/default/<action>'
]
],
It will use the default
controller any time. Do you really want it?
It is better to use just '<module:\w+>/<controller:\w+><action:\w+>' => '<module>/<controller>/<action>'
Upvotes: 1