E
E
EVOSandru62017-05-29 13:38:40
Yii
EVOSandru6, 2017-05-29 13:38:40

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>

And another .htaccess in the web folder :
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

In config/web.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',
      ]
    ],
    ...

The following rules work correctly:
'login' => 'auth/login',
 'signup' => 'auth/signup',
 'profile' => 'users/profile',
 'password' => 'auth/password',

If I enter the left part in the browser, then I get the desired right part, but there is a problem with these fragments:
'<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>',

Addresses like:
domen/pages/2
domen/pages/view/2
domen/pages/update/2
Goes to:
Not Found (#404)
The requested page does not exist.

Through {update / view}? id = {id} everything works.
I looked at it a lot, read it. But all to no avail (
I remember that in the first version I did not have such a problem.
Please tell me, masters - for what reason can I have this problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2017-05-29
@EVOSandru6

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 question

Ask a Question

731 491 924 answers to any question