Url Rule for API

I created a module inside my frontend folder (advanced app), I called "v1", now I can call my api using a url like this


This works great but I need to prepend "api" to get an url like this


How can I achieve this?

Hello kandalf, I don’t know exactly what your mean. But if you want to rewrite your url, you should add bellow line into urlManager component:

'api/v1/controller/action' => 'v1/controller/action'

Now you can access api with url : "api/v1/controller/action".

More rules for reference if using REST:

// REST patterns


'PUT,PATCH users/<id>' => 'user/update',

'DELETE users/<id>' => 'user/delete',

'GET,HEAD users/<id>' => 'user/view',

'POST users' => 'user/create',

'GET,HEAD users' => 'user/index',

'users/<id>' => 'user/options',

'users' => 'user/options',


Hope this help you.

Thank you hai doan!

I changed your rule to this

  'api/v1/<controller:\w+>/<action:\w+>' => 'v1/<controller>/<action>'

Now it works