我正在使用Yii URL管理器将类型/ events /?event = my%20event的网址重写为 /活动/我的%20event
下面的代码有效,但由于某些原因,它只在有空格时才有效。所以
events / my event,events / my-event,event / my& 20event
一切正常,但
events / test或events / newEvent
不要
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
'events/<event>' => 'events/index',
),
),
答案 0 :(得分:1)
列出最后一条规则&#39; events /&#39; =&GT; &#39; events / index&#39;,在数组的第一位
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'events/<event>' => 'events/index',
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),