CUrlManager bug

I have noticed a strange behavior in CUrlManager.

I have an application in a subfolder:




localhost/vm

And a parametrized rule for an action, let say contact:


"http://<domain:[\w_]+>.localhost/<a:[\w]+>"=>'premium/<a>',

Wich correcly parse the url http://zaccaria.localhost/vm/contact to premium/contact, that’s great.

The problem is that this rule generate the following url:

http://zaccaria.localhost/contact

WITHOUT the base url vm.

I think that the operations of parsing/creating url should be perfectly reversable, so if a url is parsed in some way, it is expectable that the url created by the same url is the original.

The problem in this asymetry is that the rule with baseUrl:


"http://<domain:[\w_]+>.localhost/vm/<a:[\w]+>"=>'premium/<a>',

Correctly create the url, but can’t parse (and is not that nice to hardcode the base url…).

The solution I found is the following:


"http://<domain:[\w_]+>.localhost/<a:[\w]+>"=>array('premium/<a>', 'parsingOnly'=>true),

"http://<domain:[\w_]+>.localhost/vm/<a:[\w]+>"=>'premium/<a>',



Wich is nothing more than a workaround. Will the staff fix this problem? Any of the rule can be a valid solution, (better the one without baseUrl), but the point is that I’d like a simmetrical behavior, I mean that the craeted url should be the same as the parsded one

I’m not clear how came that “http://zaccaria.localhost/vm/contact” gets to “premium/contact”… shouldn’t that be “premium/vm” ?

The fact is that vm is not part of the route, is the base url.

The application doesn’t lie in webroot, but webroot/vm/index.php

Is this mixing of parametrized host + baseUrl that create the problem

But in your rules you are using the domain so how would Yii know that the app is in the "vm" folder?

Is this related to this issue - https://github.com/yiisoft/yii/issues/431

in this page, if I do


echo Yii::app()->baseUrl

It prints "/vm", which means that yii correctly guessed that the application lies in a subfolder.

The problem is not in the parsing, it is awesome, the problem is the url generator, that somehow "forgot" the base path for rules with parametrized hostnames.

It should generate:

<parameter><hostname><basePath><route>

But it generates:

<parameter><hostname><route>

In the base case in wich the base path is empty, it works correctly

This chapther of the guides states quite clearly:

In fact, the rules with hard-coded hostname does not parse correctly, while the rule with the hostname doesn’t parse, but generate the correct url.

Regarding the example in the doc can you try with the following rule


"http://<domain:[\w_]+>.localhost/<a:(contact|othercontact)>"=>'premium/<a>',

This rules works fine in parsing, but wrong in generating.

The problem is that in that the generate url don’t care of the base url

Zaccaria, did you ever get this resolved? I’m running into the same issue. A parameterized hostname combined with an app that has a base URL will not properly generate and parse a URL. I can get it to properly generate or parse the URL, but not do both at the same time.

And I’d really rather not be duplicating all rules and setting some to parseOnly if I can avoid it :slight_smile: