yii2 url manager rules accept not pattern

I need configure my Yii2 UrlManager rules like this:

  1. change http://domain/site/action to http://domain/action
  2. change http://domain/module/default to http://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?

Upvotes: 0

Views: 654

Answers (1)

Shringiraj Dewangan
Shringiraj Dewangan

Reputation: 784

You can try this code

'<action:(about|contact)>' => 'site/<action>',

insted of this

'<action:\w+>' => 'site/<action>',

and it will not work then change sequence of rules

'rules' => [
    '<action:\w+>' => 'site/<action>', <-----------it will be first
    '<module:(!site)>' => '<module>/default',
],

Upvotes: 0

Related Questions