URL-经理不会路由

URL-Manager will not route

我克隆了我们的存储库并创建了与我自己的项目完全相同的 URL 规则。现在,登录后我会得到这样的错误:

Firefox:
Fehler: Umleitungsfehler
The website called is rerouting request,which never will come to an end.
This problem sometimes occures, if cookies are deactivated

Chrome:
ERR_TOO_MANY_REDIRECTS

我绝对接受在两个浏览器中使用 cookie!! 调试告诉我,我有很多 302 请求,所以 Yii 崩溃了! 我使用 Windows,而不是 LINUX,所以我不关心任何权限。 规则如下:

    'urlManager' => [
                'class' => 'yii\web\UrlManager',
                'enablePrettyUrl' => true,
                'showScriptName' => true,
                'enableStrictParsing' => true,
                'rules' => [
                    '/' => 'site/login',
                    'home' => 'site/index',
                    'logout' => 'site/logout',
                    'contact' => 'site/contact',
                    'signup' => 'site/signup',
                    'reset' => 'site/request-password-reset',
                    '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
                    '<action:(contact|captcha)>' => 'site/<action>'
                ],

这是前端配置:

<?php

$config = [
    // LZA 17-07-30 
    'sourceLanguage' => 'de-DE',
    'language' => 'de-DE',
    // LZA 17-07-30 siehe  Funktionen in  http://demos.krajee.com/grid#module    
    'components' => [
        'request' => [
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' => '4lD2RxDNkC4ckpwxTmkDzOLIvk0JMs3F',
        ],
    ],
];

if (!YII_ENV_TEST) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = [
        'class' => 'yii\debug\Module',
    ];

    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
        // LZA 17-07-30 CRUD
        'generators' => [// customized CRUD generator
            'crud' => [
                // 'class' => 'app\myCrud\crud\Generator', // LZA 17-07-20 die Klasse von CRUD generator
                'class' => '\common\wsl_dev\wsl_crud\crud\Generator', // LZA 17-07-20 die Klasse von CRUD generator
                'templates' => [
                    'myCrud' => '/@common/wsl_dev/wsl_crud/crud/default', //LZA 17-07-20 Templatename und Templatepfad
                ]
            ]
        ],
            // LZA 17-07-30 CRUD        
    ];
}

return $config;

如果我停用 URLManger,setting

 'enablePrettyUrl' => false,

一切正常。 如果我像这样手动输入 Url:

http://localhost/yii2_perswitch/frontend/web/yiic.php/home

也一切正常

任何想法,如何解决这个问题? 我删除了我所有的cookies,没有任何影响!

解决方案一:

从 web/index.php 启用调试模式(取消注释这两行):

defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');

并且您可以准确地看到导致问题的原因。

Redirected too many times error was because the 777 permissions for runtime and assets folder were not set.

方案二:

我认为问题与cookie 的路径或域有关。我相信此信息可能会有用。

https://github.com/samdark/yii2-cookbook/blob/master/book/cookies.md