Urlmanager Having Different Controller/action With Same Number Of Arguments


I’m facing a problem as below:

In my config/main.php, I have



These are two different controller/actions with different parameter names. However, it always defaults to the first rule, whatever it may be. Is there a way to tell Yii how to differentiate between the two rules based on same number of parameters/arguments but different parameter names? Or does it HAVE to be different number of parameters for each controller/action?

Your advice and help will be much appreciated.



Hi Omar, welcome to the forum.

It’s up to the regular expressions that you use for the url manager rules.

If the given url falls into the 1st pattern, then it will be routed to the 1st route, without checking the 2nd rule and its pattern. So, try to come up with the pattern that is only applicable to "country" or "airline", then you can solve the problem.

Hi softark,

Thank you for your advice. I’m not very good at regular expressions so can you please help me a bit further and suggest a regular expression that could work. Both my controller/actions expect, for example, United States for abc/index and Air Blue for xyz/view. One argument for both actionIndex and actionView functions in different controllers.

Thanks & Kind Regards,



I’m sorry, but I don’t get what you mean by the sample.

How do you know ‘abc’ stands for ‘United States’ and ‘xyz’ stands for ‘Air Blue’?


Sorry about the confusion. Here is my URLManager:





			'&lt;lang&gt;'=&gt;array('site/index', 'urlSuffix'=&gt;''),

			'&lt;lang&gt;/site/&lt;view:(privacy)&gt;' =&gt; 'site/page',

			'&lt;lang&gt;/site/contact' =&gt; 'site/contact',








For URLs,




only the first rule is used by Yii, breaking the other controller/action.

Both ‘<lang>/<airline:.?>’ and '<lang>/<cnty:.?>’ have exactly the same regular expression pattern, so ‘country/index’ will never have the chance to be applied.

For example, if you are sure that all the air lines have ‘Air’ or ‘Aero’ in their names, then you could do something like this:



But probably it’s better to adopt a simple solution:






Hi softark,

Thank you very much for your help. I have implemented your suggestion after getting approval from my client and everything is now working well. :)

Thanks again.

Kind Regards,

Muhammad Omar