Rustam
Rustam

Reputation: 273

How to change url structure of yii2 (from controller/view?id= to view/id)

How to change url structure of yii2 (from controller/view?id= to controller/view/id)

Upvotes: 0

Views: 620

Answers (1)

arogachev
arogachev

Reputation: 33548

Seems like you already enabled pretty url rules, so you need to add url rule. Add this to your app config:

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

I want url to be like :test.advanced.loc/member/profile/view/c_id/1. Currently, it is test.advanced.loc/member/profile/view?c_id=1

In this case url rule should be:

'member/profile/view/c_id/<c_id:\d+>' => 'member/profile/view',

More info and examples can be found in offical docs.

Upvotes: 1

Related Questions