I need configure my Yii2 UrlManager rules like this:
- change
http://domain/site/actiontohttp://domain/action - change
http://domain/module/defaulttohttp://domain/module
so far what I have done:
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<module:(!site)>' => '<module>/default',
'<action:\w+>' => 'site/<action>',
],
],
when I trying access module it return 404. But when I remove '<action:\w+>' => 'site/<action>', access module again will show as module/default page. So how to solve this?
http://domain/somethinghow is the router supposed to know ifsomethingshould be module or action?yii\web\UrlRuleand override itsparseRequestmethod to check existence of action. Or you can simply add some prefix to your url so you can determine if route belongs to site controller or module. For example usehttp://domain/m/somethingfor modules andhttp://domain/somethingfor actions in site controller.