help with url pattern rules

Hi,

I have three url rules in config main.php:


'<controller:(c1|c2|c3|gii)>' => '<controller>',

'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

'<controller:\w+>/<id:\d+>'=>'<controller>/',

It workds fine when the url appears as http://127.0.0.1/c1

but It doest not work when the url is http://127…0.0.1/c1/view where view is the action name,the error from apache server says could not find url specified.

I guess the second url above is matched by the first rule, and does not propagate to the second rule. So how can I match the second url to the second rule while still preserve the first rule functionality? thanks for any help.

Read Edit2

Try:




'<controller:(c1|c2|c3|gii)/>/<action:\w+>' => '<controller>/<action>',



Is that what you wanted?

Next time look at which URL actually was requested and debug from there. I think it was “http://127.0.0.1/c1”. Because everything “’<controller:(c1|c2|c3|gii)>’ => ‘<controller>’,” ignores everything after the controller when the controller is c1, c2, c3 or gii.

edit:

After a little thought, this should be enough




'<controller:(c1|c2|c3|gii)/>/<action:\w+>' => '<controller>',



edit2:

Disregard that. I think I was completely wrong.




'<controller:\w+>' => '<controller>',

'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',



This should be enough to redirect to a controller and action no matter what it’s name is. But I’m now more confused about CUrlManager than before :smiley:

hofrob

Hi hofrob,

thank you very much for your help. unfortunately, I have just added the last rule. I have all rules like this:


'<controller:(c1|c2|c3|gii)>' => '<controller>',

'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

'<controller:\w+>/<id:\d+>'=>'<controller>/',

'<name:[a-zA-Z0-9_-]+>'=>'user/profile',

in this case, your last proposal edit2(see below) will not work, since I need to dispatch the username to user/profile, and not to be interpreted as a controller id.


'<controller:\w+>' => '<controller>',

'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

As to your other suggestion edit1(see below),it will only work when the url is http://127…0.0.1/c1/view , but won’ work when url is http://127…0.0.1/c1,


'<controller:(c1|c2|c3|gii)/>/<action:\w+>' => '<controller>/<action>',

'<controller:(c1|c2|c3|gii)/>/<action:\w+>' => '<controller>',

any other ideas? thanks again.

Ok, then this should do it:




'<controller:(c1|c2|c3|gii)>' => '<controller>',

'<controller:(c1|c2|c3|gii)>/<action:\w+>'=>'<controller>/<action>',

'<controller:\w+>/<id:\d+>'=>'<controller>/',

'<name:[\w_-]+>'=>'user/profile',



Every request that is not "host/c1…", "host/c2…", "host/c3…" or "host/gii…" will use the last rule. That means that there must not be usernames like "cX" and "gii".

hofrob