Yii - Rewrite Url Via Urlmanager

I’m trying to rewrite an url created via createUrl method:


In urlManager, I set a rule that almost like the instruction:



    'showScriptName' =>false,


       // core




       //this url

       'user/<id:\w+>'=>array('user/user/view', 'urlSuffix'=>'.html'),



It worked without any problem.

Now I want to remove the .html extension with the rule below instead:


And it returns error

. It seems that the regex pattern


used to rewrite url, is no longer correct. How could I fix it?

Put this rule on the top of the rules definition. Also, if user id is numerical, you should use <id:\d+> instead of <id:\w+>

Thank you, rob006. You pointed out the exact problem. Did that mean some of my URLs are duplicated?

Url manager gets first matching rule, when resolves urls. Url like example.com/user/1 match rule ‘<controller:\w+>/<id:\d+>’=>’<controller>/view’ so this is used. You just need put more specific rules on the top.