urlManager

Hi!

I wrote the rule in main.php config file:


'urlManager'=>array(

   'urlFormat'=>'path',

   'showScriptName'=>false,

   'rules'=>array(

        'post/page/<page:\d+>'=>'posts/index',

   ),

),

It represents my url as: /post/page/2, /post/page/3 etc… But for the first page it looks like: /posts/index . And I want it to shows as /post/page/1 . How can I do it?

Try:




'urlManager'=>array(

   'urlFormat'=>'path',

   'showScriptName'=>false,

   'rules'=>array(

        'post/page/<page:\d+>'=>'posts/index',

        'post/page/1'=>'posts/index',

   ),

),



So easy :)

Thank you very much! I thought if we will write posts/index two times it may occures an exception. But it works fine! I cant understand how these two rules works together.

Seems not obvious, but it’s just logic… Yii tries to find the corresponding rule by checking them one by one. He skips 1st rule, but finds the second when the “page” parameter is not passed.