3

我正在使用 PHP Yii 框架开发网站,我现在是堆栈,我需要启动 gii,但我不能这样做。当我输入 www.example.com/index.php/gii 或 www.example.com/gii 时,它给了我这个错误:

    /gii/default/login // <- website redirects to here

    This webpage has a redirect loop
    The webpage at http://www.example.com/gii/default/login has resulted in too many redirects.
Clearing your cookies for this site or allowing third-party cookies may fix the problem. 
If not, it is possibly a server configuration issue and not a problem with your computer.

我不认为错误是因为修改了 htaccess 和 main 配置,但无论如何这里是 main.php 配置文件:

    'urlManager'=>array(
        'urlFormat'=>'path',
        'showScriptName'=>false,
        'rules'=>array(
            'site/page/<view:\w+>'=>'site/page',
            '<controller:\w+>/<cact:\w+>/<action:\w+>'=>'<controller>/<cact>',
            '<controller:\w+>/<id:\d+>'=>'<controller>/view',
            '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
            '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
        ),
    ),

和 .htaccess :

Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on

#non-www to www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule ^.*$ /index.php [L]

那你能帮我吗?

4

5 回答 5

6

要使用此路径:index.php?r=gii/default/login,您必须关闭 url 管理器 /protected/config/main.php

于 2012-10-08T08:50:54.520 回答
5

也检查一下urlManagerrules这对我来说是个问题:

'components' => array(
    'urlManager' => array(
        'urlFormat' => 'path',
        'showScriptName' => false,
        'rules' => array(
            // ...
            // will handle `gii/default/login` uri and makes infinite redirection loop circle
            '<controller:\w+>/<action:\w+>/<sub_action:\w+>'=>'<controller>/<action>',
            // ...
        ),
     ),
 ),
于 2012-11-12T13:22:16.210 回答
4

检查配置文件中的 gii 模块是否存在并且未注释。如果 gii 不在那里,你应该将它添加到模块数组中。

'modules'=>array(
    'gii'=>array(
        'class'=>'system.gii.GiiModule',
        'password'=>***choose a password***
    ),
),

gii 的更多信息在这里

于 2012-03-14T17:47:18.357 回答
4

就像FelikZ 提到\w+的那样,这可能是因为您在使用而不是默认的规则中创建了第三个参数,\d+因此将匹配“gii”作为控制器,“默认”作为操作,“登录”作为 ID(或子行动,或任何提到的)。

我的规则如下所示:

'<controller:\w+>/<action:\w+>/<id:\w+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

解决方法是添加以下作为第一条规则,以使 gii 到达正确的位置:

'gii/<controller:\w+>/<action:[\w-]+>' => 'gii/<controller>/<action>',

这应该使您的整个urlManager配置如下所示:

'urlManager'=>array(
    'urlFormat'=>'path',
    'showScriptName'=>false,
    'rules'=>array(
        'gii/<controller:\w+>/<action:[\w-]+>' => 'gii/<controller>/<action>',

        '<controller:\w+>/<action:\w+>/<id:\w+>'=>'<controller>/<action>',
        '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
    ),
),
于 2014-07-16T10:40:55.593 回答
1

出现此问题是因为 OP 的两个会话,例如 cookie PHPSESSID 有两个域 domain .site.ru 和 admin.site.ru 两个不同的会话。删除 PHPSESSID cookie 并登录 gii

于 2013-11-08T03:06:15.423 回答