I can't configure the Yii2 CNC
In the file web.php 'urlManager' settings the last rule does not apply to urls of type http://yii2/default?view=about I don't understand what the error is.
. htaccess in the project root looks like this
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/(web)
RewriteRule ^assets/(.*)$ /web/assets/$1 [L]
RewriteRule ^css/(.*)$ web/css/$1 [L]
RewriteRule ^js/(.*)$ web/js/$1 [L]
RewriteRule ^images/(.*)$ web/images/$1 [L]
RewriteRule (.*) /web/$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /web/index.php
. htaccess in the web folder
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php
Configuration in the file web.php in the config folder. baseUrl is specified with the given value
'components' => [
'request' => [
'baseUrl'=> ''
],
]
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'enableStrictParsing' => false,
'rules' => [
'<action:\w+>' =>
'news/<action>',
'<action:\w+\W\w+>' =>
'news/<action>',
'<action:\w+\W\w+>' =>
'news/default?view=<action>' - та самая настройка, нерабочая
],
],
Tell me good people what I'm doing wrong.
In the controller, the page is not returned using actionDefault
, and
function actions(){
return [
'default' => [
'id' => 'about',
'class' => 'yii\web\ViewAction',
'viewPrefix' => 'default'
]
];
}
1
Author: Alexshev92, 2019-06-07
1 answers
Теперь при обращении к url http://yii2/about получаю нужную страницу по пути корень_сайта/views/news/default/about.php
Запись в контроллере
function actions(){
return [
'about' => [
'class' => 'yii\web\ViewAction',
'viewPrefix' => 'default',
'defaultView' => 'about'
]
]
}
в urlManager по этому запросу регулярка не потребовалась
0
Author: Shura Karelin, 2019-06-07 09:22:33