Answer the question
In order to leave comments, you need to log in
Why Yii2 CNC addresses with id don't work?
Good afternoon,
Such a problem, it is not possible to configure the CNC with id . I fly away to 404
.htaccess at the root of the site:
AddDefaultCharset utf-8
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI} ^/.*
RewriteRule ^(.*)$ web/$1 [L]
RewriteCond %{REQUEST_URI} !^/web/
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ web/index.php
</IfModule>
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
...
'components' => [
'request' => [
'cookieValidationKey' => '****',
'baseUrl' => '',
],
...
]
...
'urlManager' => [
'showScriptName' => false,
'enablePrettyUrl' => true,
'rules' => [
'login' => 'auth/login',
'signup' => 'auth/signup',
'profile' => 'users/profile',
'password' => 'auth/password',
/////////////////////////
'<module:\w+>/<controller:\w+>/<id:\d+>' => '<module:\w+>/<controller>/view',
'<module:\w+>/<controller:\w+>/<action:\w+>/<id:\d+>' => '<module:\w+>/<controller>/<action>',
'<module:\w+>/<controller:\w+>/<action:\w+>' => '<module:\w+>/<controller>/<action>',
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
'<action>'=>'site/<action>',
'' => 'site/index',
]
],
...
'login' => 'auth/login',
'signup' => 'auth/signup',
'profile' => 'users/profile',
'password' => 'auth/password',
'<module:\w+>/<controller:\w+>/<id:\d+>' => '<module:\w+>/<controller>/view',
'<module:\w+>/<controller:\w+>/<action:\w+>/<id:\d+>' => '<module:\w+>/<controller>/<action>',
'<module:\w+>/<controller:\w+>/<action:\w+>' => '<module:\w+>/<controller>/<action>',
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
Answer the question
In order to leave comments, you need to log in
the problem is that you do not have the correct sequence of rules, for example, it should be like this:
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>'
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<module:\w+>/<controller:\w+>/<id:\d+>' => '<module:\w+>/<controller>/view',
'<module:\w+>/<controller:\w+>/<action:\w+>' => '<module:\w+>/<controller>/<action>',
'<module:\w+>/<controller:\w+>/<action:\w+>/<id:\d+>' => '<module:\w+>/<controller>/<action>',
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question