CHtml::link not generating URL in path format


I have urlFormat set to ‘path’ in my main config.

I’m trying to generate a link in my view file. I’m using the following code:

CHtml::link($data->totalCount.' items', array('collection/browse', 'by' => 'tag', 'id' => $data->id))

I’m trying to build a link with the format:

But the link that the code generates is:

CHtml::link uses normalizeUrl(), which uses createUrl(). The special topic page ( says that createUrl will use the ‘path’ format if it is configured this way, but it doesn’t seem to be doing that.

Is this a bug, or am I doing something wrong. Should I just use hardcoded anchor link tags instead of CHtml::link?



this should be configurable in your config/main.php in the urlManager. Can you please paste your urlManager setup.

If you would just like to eliminate the query string and puts the GET parameters into the path info part of URL you should just define ‘urlFormat’=>‘path’, in your url manager and leave the urlRules empty.

Another approach would be to have the following url rule:


, which will further remove the GET parameters from the url and will bind only their values.

Please note that <by:\w+> allowes the by tag to be populated with almost any character. If you would like to make it more strict you could use (tag|tag2|tag3…etc) if you have a certain set of options.

hope this helps


Thanks so much bettor. That worked perfectly!

I didn’t realise the rules also determined how URLs were generated, I thought they were just used to route the request.



This section of the guide can be very helpful: