【发布时间】:2016-08-28 13:44:25
【问题描述】:
我在yii2上学习, 制作 url 路由时遇到问题。 这是我的网址配置
'urlManager' => [
'class' => 'yii\web\UrlManager',
// Disable index.php
'showScriptName' => false,
// Disable r= routes
// 'enableStrictParsing' => false,
'enablePrettyUrl' => true,
'rules' => array(
'category/<id:\S+>' => 'category/detail',
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
'request-password-reset' => 'site/request-password-reset',
'reset-password/<token:\S+>' => 'site/reset-password',
'profile/<id:[0-9a-zA-Z\-]+>/?' => 'profile/user',
'logout' => 'site/logout',
'login' => 'site/login',
),
],
问题出在配置文件路由中。 情况是这样的:
- http://localhost/myapps/profile/some-url/ -> 使用添加的斜线 网址结束
- http://localhost/myapps/profile/some-url -> url 末尾没有斜杠不起作用,错误 404
- http://localhost/myapps/profile/someurl -> 不工作错误 404。
- http://localhost/myapps/profile/first-second-third -> 我们的不带斜线到底是有效的
我真的很困惑,我一直在这里寻找以前的问题,但没有尝试任何适用于我的案例。
有人可以帮我解决我的问题吗?
【问题讨论】:
标签: php url yii2 url-routing