Problem with UrlManager

When requesting the URI "/" I get:

using the following config:


'urlManager' => array(

	'cacheID' => false,

	'caseSensitive' => true,

	'showScriptName' => false,

	'urlFormat' => 'path',

	'urlSuffix' => '/',

	'useStrictParsing' => true,

	'rules' => array('' => 'test/portal'),



If I disable useStrictParsing it works. The problem is obviosuly somewhere here (in the CUrlManager class):

if($manager->useStrictParsing && $pathInfo===$rawPathInfo

	&& ($this->urlSuffix!='' || $this->urlSuffix===null && $manager->urlSuffix!=''))

	throw new CHttpException(404,Yii::t('yii','Unable to resolve the request "{route}".',


Currently I use this fix in my custom i18n module that will re-init the urlmanager after that:

if ('/' === $_SERVER['REQUEST_URI'])


	Yii::app()->urlmanager->useStrictParsing = false;


Can anyone reproduce that?

Why not add


to your rules? I did the same, too.

I have

'' => 'test/portal'

in the config.

Does the above urlmanager config work for you when you request the index page (eg

Yes, it does work for me.

Please make sure your defaultController is test, and in that class, defaultAction is portal.

Doesn’t work for me. If I don’t define ANY url-rule, don’t touch defaultController/defaultAction and request the index page with the urlmanager config posted (the single rule excluded of course), it says:

As soon as I add my fix it says:

Could you please share your urlManager config?

See first post ;)

Sorry, I forgot you already included.

I’d remove the url suffix. Doesn’t make sense as Apache already takes care of your directories.

(I know it’s good-looking when an url ends with a slash by the way. :P)

Well I want to have trailing slashes for seo-reasons. If I remove the suffix it works like expected, but then the urlmanager->createUrl() function doesn’t append a trailing slash anymore.

Well then you should extend createUrl() and not enforce trailing slash via url rules.

I don’t think this has much effect on seo by the way. Could you show some evidence?

Hehe, I could do that, of course. But I’m posting here for a reason - urlSuffix/useStrictParsing obviously doesn’t work like expected.

No evidence, I don’t work at Google :D

I still feel that using slash for suffixing urls is a bad idea. I created an issue ticket, though.

I think we should omit the url rule for empty string and let Yii render defaultController/defaultAction (this only applies to strict parsing).

An authentic article will do. :)


Why that? If I define the rule "" => "my/test" then I expect the rule to do what I want. The defaultController/defaultAction should only render if there is no matching "empty" url-rule or if there are no rules at all defined.

Sorry I don’t have one. Just expirience and habit. I think it’s the best way, everyone should make their own expirience though. :)

Correct. Although, the rule for the front page is defined 100% of the time. After all, what is defaultController and defaultAction for?

I’ve just noticed my fix doesn’t work anymore when requesting for example “/test/” instead of “/”. The combination of urlSuffix = “/” and useStrictParsing = true causes too much problems. I have disabled strictParsing now and everything works without my fix and without any problems.

I suggest the useStrictParsing and urlSuffix feature should be re-written or extended so it works like expected. For example the getPathInfo() function in CHttpRequest trims the first/last "/" from the returning path. That means we will never get a match here when strictParsing is enabled and urlSuffix is "/".

I updated the issue ticket accordingly containing the problem of rtrim.

Thanks man.

I’ve looked into this again.

An easy fix would be to modify the parseUrl() function of CUrlManager this way:




if($manager->useStrictParsing && (($this->urlSuffix===null && $manager->urlSuffix==='/') || $this->urlSuffix==='/'))



// URL suffix required, but not found in the requested URL

if($manager->useStrictParsing && $pathInfo===$rawPathInfo

	&& ($this->urlSuffix!='' || $this->urlSuffix===null && $manager->urlSuffix!=''))

	throw new CHttpException(404,Yii::t('yii','Unable to resolve the request "{route}".',


I’m looking forward to see this fix in an upcoming version. For now I will extend the CUrlManager component.

pestaa, if you could update once more I’d be happy! Thanks in advance. :)

EDIT: Actually, the fix takes place in CUrlRule and not in CUrlManager.