routesyii2yii-url-manager

Yii2 urlManager rule for `&id=`


I'm trying to configure the Yii2 URL Manager.

Now my config file looks like this:

'urlManager' => [
  'enablePrettyUrl' => true,
  'showScriptName' => false,
  'rules' => [
    '<controller:\w+>/<id:\d+>' => '<controller>/view',
    '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
    '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
  ]
],

With and without rules i always get this route:

/frontend/web/user/default/profile?id=1

How can i set up rules for url with ?id= so that they are like:

/frontend/web/user/default/profile/1

Solution

  • You could simply add a default rule for module, e.g. :

    'rules' => [
        '<module>/<controller>/<action>/<id:\d+>' => '<module>/<controller>/<action>',
        ...
    ],