我正在使用高级模板。
我在 SiteController 上创建了所有操作,因此我所有的 url 都是domain.com/site/something,并且我需要从 url 中删除“site”一词,这样它将是domain.com/something。
我根据以下规则尝试了这个问题 https://stackoverflow.com/questions/29577022/remove-controller-name-from-urls-in-yii2
'urlManager' => [
'class' => 'yii\web\UrlManager',
'showScriptName' => false,
'enablePrettyUrl' => true,
'rules' => array(
'/<action:\w+>/<id:\d+>' => 'site/<action>',
'/<action:\w+>' => 'site/<action>',
'/noticia/<slug>' => 'site/noticia',
),
],
也尝试过这个基于这另一个问题 https://stackoverflow.com/questions/38272745/yii2-how-to-remove-site-index-and-page-parameter-from-url:
'urlManager' => [
'class' => 'yii\web\UrlManager',
'showScriptName' => false,
'enablePrettyUrl' => true,
'baseUrl' => 'http://localhost/websites/transcita/app/frontend/web',
'rules' => array(
[
'pattern' => '<action:\w+>',
'route' => 'site/<action>'
],
[
'pattern' => '<action:\w+>/<id:\d+>',
'route' => 'site/<action>'
],
'/noticia/<slug>' => 'site/noticia',
),
],
但两者都不起作用。当我输入domain.com/something 时,我收到 404。
我也尝试过没有第一个 / ,但它也不起作用。
有什么想法吗?