3

I am developing website with PHP Yii Framework and I am now stack, I need to start gii, but I can't do this. when i type www.example.com/index.php/gii or www.example.com/gii it gives me this error :

    /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.

I don't think that the error is because of modified htaccess and main configuration, but anyway here is main.php configuration file:

    '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>',
        ),
    ),

and .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]

So can you help me, please?

Irakli
  • 1,151
  • 5
  • 30
  • 55

5 Answers5

6

To use this path: index.php?r=gii/default/login , you must turn OFF the url manager in /protected/config/main.php

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
Johnny Walker
  • 61
  • 1
  • 2
5

Also check urlManager's rules. That was the issue for me:

'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>',
            // ...
        ),
     ),
 ),
FelikZ
  • 2,976
  • 4
  • 32
  • 41
4

Like FelikZ mentioned, this might be because you have created a third param in a rule that uses \w+ instead of the default \d+ and hence will match "gii" as the controller, "default" as the action and "login" as the ID (or sub action, or whatever is mentioned).

My rules looked like the following:

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

The fix is to add the following as the very first rule in order to make gii hit the right place:

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

Which should make your entire urlManager config look something like the following:

'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>',
    ),
),
Community
  • 1
  • 1
h2ooooooo
  • 39,111
  • 8
  • 68
  • 102
4

Check if the gii module in your configuration file is there and it is uncommented. If gii is not in there you should add it within the module array.

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

More info for gii here

Noki
  • 451
  • 3
  • 6
  • It is allready set in main.php, I was able to use Gii until I changed default urls to user friendly urls – Irakli Mar 14 '12 at 18:21
  • 1
    To the link i posted at the second block of code it says what you have to do if you are using user friendly urls. – Noki Mar 14 '12 at 18:24
  • Thank you very much, everything works as needed! Thank you, again! – Irakli Mar 14 '12 at 18:40
1

This problem occurs because of the two sessions of the OP, for example cookie PHPSESSID there two domains domain .site.ru and admin.site.ru two different sessions. Delete PHPSESSID cookies and login to gii

Mike Bazhenov
  • 128
  • 1
  • 9