고급 템플릿을 사용하고 있습니다. SiteController에서 내 모든 작업을 만들었으므로 모든 URL은 domain.com/site/something입니다. URL에서 "site"라는 단어를 제거해야 domain.com/something이됩니다.Yii2 : 컨트롤러에서 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',
),
],
을하지만 어느 쪽도 작동하지된다
나는이 this other question에 따라 시도 this question'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',
),
],
에 따라 다음과 같은 규칙을 시도했다. domain.com/something을 입력하면 404가 표시됩니다. 나는 또한 첫 번째 시도없이/시도 했는데도 작동하지 않았다.
의견이 있으십니까?
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'enableStrictParsing' => false,
'rules' => [
// ...
// last rule
'<action:(.*)>' => 'site/<action>',
],
],
감사합니다! 이것은 완벽하게 작동했습니다! 그 변화가 트릭을했기 때문에 \ w +와 (. *)의 차이점을 읽을 수있는 링크가 있을까요? –
여기에 reg expr에 대한 훌륭한 설명이 있습니다 : https://regex101.com/. \ w +는 문자, 숫자 또는 밑줄과 일치합니다. * 0 개 이상의 문자를 매시합니다. 어쩌면 당신의 행동은 하나 이상의 단어로 구성 될 수 있습니다. –