routing urlManager for domain/username/action


I’m new to Yii. I’m liking what I see, but I have a problem.

I’m trying to create routes that have usernames as the first parameter.

I’ve worked out how to get the index to route to the login action of the user controller:

'<user:\w+>' => 'user/login'

But if I try to route to a specific action I get a 404. eg /myusername/myaction

'<user:\w+>/<action:\w+>' => 'user/<action>'

What am I doing wrong?

Please read this guide’s section:

Hi Andy. I have read the guide. I can’t see what I’m doing wrong.


'<user:\w+>/<action:\w+>' => 'user/<action>'

I’m defining two parameters; user and action. Both can be any string containing letters, digits, and underscores, and are separated by a forward slash.

The route is for the user controller, using the action defined at the end of the pattern.

I can’t see how it is fundamentally different from the default:


Solved it.

I had another route previous to this one that was catching it.


Shouldn’t it be:

'<user:\w+>/<_a>' => 'user/<_a>',


Yes that works too. I didn’t realise that you could miss out the regex if you just want to match everything.

This works as well:

'<user>/<action>' => 'user/<action>'