1

I was looking to change controller name in URL. Which, we can do by renaming the controller name in module. But, Through URL manager if we can do it. It will be better.

Module: user, Controller: api, Action: index

Right now,

'urlManager' => [
  'enablePrettyUrl' => true,
  'showScriptName' => false,
  'rules' => [
        '<controller:(api)>/<action:\w+>/<id:[a-z0-9]+>' => 'user/<controller>/<action>',
        '<controller:(api)>/<action>' => 'user/<controller>/<action>',
    ]
];

And, I can access it through.

http://dev.example.com/api/index

But, I was looking to change it to

http://dev.example.com/world/index

How can I do it? Any help/hint/suggestion is appreciable.

2 Answers 2

1

You can create custom url rules by adding items to the rules array.

So, in your case insert this into the rules array

'world/index' => 'api/index'

You can read more about URL rules here.

Sign up to request clarification or add additional context in comments.

Comments

0

also you use ControllerMap

it useful when you are using third-party controllers and you do not have control over their class names.

below code in component in main.php in advance or web.php in basic for example:

    'controllerMap' => [           
        'api' => 'app\controllers\WorldController',
                        ]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.