Yii2 urlManager,我想编写一个如下所示的正则表达式。
*.*com/bj/haidian/
很好。
*.*com/bj/haidian
不起作用。
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<module:\w+>/<controller:\w+>/<action:\w+>' => '<module>/<controller>/<action>',
"<controller:\w+>/<action:\w+>/<id:\d+>" => "<controller>/<action>",
"<controller:\w+>/<action:\w+>" => "<controller>/<action>",
'<module:\w+>/<action:\w+>/<id:\d+>' => '<module>/default/<action>',
'<module:\w+>/<controller:\w+>' => '<module>/<controller>/index',
'bj|sh|gz|sz|cd|xa|wh|hz|tj|dl/?'=>'/sem/weight',
'bj|sh|gz|sz|cd|xa|wh|hz|tj|dl/<district:[0-9a-zA-Z\_\-]+>/?' => '/sem/weight',
'bj|sh|gz|sz|cd|xa|wh|hz|tj|dl/<district:[0-9a-zA-Z\_]+>/<cond:[0-9a-zA-Z\_]+>/?' => '/sem/weight',
],
],
答案 0 :(得分:0)
您的规则应该在default
规则或parameterized
路由之前,不在它们之后,否则您的规则在我身边正常工作我只测试了所有3个规则,只需将序列更改为以下内容。 / p>
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'bj|sh|gz|sz|cd|xa|wh|hz|tj|dl/?'=>'/sem/weight',
'bj|sh|gz|sz|cd|xa|wh|hz|tj|dl/<district:[0-9a-zA-Z\_\-]+>/?' => '/sem/weight',
'bj|sh|gz|sz|cd|xa|wh|hz|tj|dl/<district:[0-9a-zA-Z\_]+>/<cond:[0-9a-zA-Z\_]+>/?' => '/sem/weight',
'<module:\w+>/<controller:\w+>/<action:\w+>' => '<module>/<controller>/<action>',
"<controller:\w+>/<action:\w+>/<id:\d+>" => "<controller>/<action>",
"<controller:\w+>/<action:\w+>" => "<controller>/<action>",
'<module:\w+>/<action:\w+>/<id:\d+>' => '<module>/default/<action>',
'<module:\w+>/<controller:\w+>' => '<module>/<controller>/index',
],
],