简体   繁体   中英

Yii2 change url structure

Instead of have:

http://www.example.com/affiliate?ref=123456546546

I prefer to have

http://www.example.com/affiliate/ref/123456546546

Is it possible to pass GET param without changing .htaccess and keep my desired structure ?

try to add an rule to your UrlManager I guess your controller is affiliate and your action index

'urlManager' => [
...
   'rules' => [
      '<controller:(affiliate)>/ref/<ref:\d+>' => '<controller>/index',
   ]
...
]

I guess if you set custom rules you also have to add the following so that the default url's are still working.

 '<controller:\w+>/<id:\d+>' => '<controller>/view',
 '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM