【发布时间】:2018-07-03 04:18:32
【问题描述】:
我有以下网址:
http://test.local/index.php?r=site%2Findex&slug=blog-detail
http://test.local/index.php?r=site%2Findex&slug=blog
http://test.local/
我想得到:
http://test.local/blog
http://test.local/blog-detail
http://test.local/
我将所有请求发送到SiteController::actionIndex($slug),我正在使用基本应用程序模板。
到目前为止,我已经能够隐藏index.php 和site/index。
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<slug\w+>' => 'site/index',
],
]
但似乎\w+ 与- 的字符串不匹配。此外,如果 slug 为空,则应显示:http://test.local/。
【问题讨论】:
标签: yii2 yii2-basic-app yii2-urlmanager