使用Yii urlManager的非标准网址

时间:2012-01-26 13:11:45

标签: php regex url yii pcre

我需要使用像<controller>.<action>这样的网址,例如:api.wwwhost.com/index.php?r = people.top

所以,我试过写模式

'urlManager'=>array(
    'urlFormat'=>'path',
    'showScriptName'=>false,
    'caseSensitive'=>false,
    'useStrictParsing'=>true,
    'rules'=>array(
        '<controller:\w+>.<action:\w+>' => '<controller>/<action>',
    ),
),

但它不起作用。据我所知,符号“。”不包含在“\ w +”中。

我的错误在哪里?

1 个答案:

答案 0 :(得分:1)

对我来说,当处于“路径”模式('urlFormat'=>'path')时,我无法使用index.php?r=people/top样式的网址。当我处于?r=模式时,我的path样式网址都不起作用。你经历过同样的事吗?

当我处于“获取”模式('urlFormat'=>'get')时,他们会这样做,但是在获取模式下,URL规则不会被处理,并且默认情况下只会使用“/”作为分隔符。

当我使用此样式网址时,您可以为我编写DID代码:

api.wwwhost.com/people.top

设置“路径”模式(即'urlFormat'=>'path')时,请务必正确设置.htaccess文件以使用它(隐藏index.php文件)。更多信息请参见Yii Guide about URLs

相关问题