urlManager struggle with trailing slash

Hi all!

I’m trying to make 2 main rules in my url manager configuration.

Rule 1 - to display pages without parameters

Rule 2 - to display pages with parameters

Page identifier is passed in the query string and it sometimes does containt slashes:


localhost/foo/bar/

Here foo/bar is the page identifier. (Note the trailing slash.)

On the other hand sometimes some parameter needs to be passed to certain pages. I’m trying to accheive this by making an url without trailing slash:


localhost/foo/bar/parameter

It seems like I need some regular expressions magic for first rule, but just can’t get it…

I had to separate each rule into 2, but that is not an issue.

Current config follows.




'urlManager'=>array(

        'urlFormat'=>'path',

        'rules'=>array(

            // Rule 1. parse request with parameter (without trailing slash)

            array(

                'site/page',

                'pattern'=>'<pid:.+>/<spid:.+[^\/]$>',

                'parsingOnly'=>true

                ),

            // Rule 2. parse request without parameter (with trailing slash)

            array(

                'site/page',

                'pattern'=>'<pid:.*>',

                'parsingOnly'=>true,

                'urlSuffix'=>'/',

                ),

            // Rule 3. create url with parameter (without trailing slash)

            array(

                'site/page/<pid>/<spid>',

                'pattern'=>'<pid:.*>/<spid:.*>', 

                ),

            // Rule 4. create url without parameter (with trailing slash)

            array(

                'site/page/<pid>',

                'pattern'=>'<pid:.+>',

                'urlSuffix'=>'/'

                ),

        ),

),



Would appreciate any guidance on solving this problem.

It would be ok to add some nicely looking separator before parameters if it is really needed.

Thanks in advance.