1

I've problem with url in Yii. when I enter URL like this,

http://localhost/yii_project/index.php/gii/default/login

it doesn't opens that page and it redirects to home page.

But when I enter url like this,

http://localhost/yii_project/index.php?r=gii/default/login

it open successfully.

I don't want to use index.php?r=. I want to display it index.php/gii/..

2 Answers 2

1

Change /protected/config/main.php as

'urlManager' => array(
        'urlFormat' => 'path',
        'showScriptName' => false, 
        'rules' => array(
            'search/<action:\w+>/'=>'dashboard/search/<action>',
            'view/<action:\w+>/'=>'dashboard/view/<action>',
        ),

for more Info Hide index.php in yii

Sign up to request clarification or add additional context in comments.

1 Comment

Change 'showScriptName' => true when you want to show index.php in your URL
0

This is Yii1 or Yii2 you are using ?

For Yii2 Basic App (current version), open @app/config/web.php and add the following code:

This will result in this: http://localhost/yii_project/gii/default/login

If you wanted the index.php included also then change a line to 'showScriptName' => true, return [ ... , 'components' => [ .... ,

        // below is the new section to include:
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'enableStrictParsing' => false,
            //'suffix' => '.php',
            //'cache' => 'cache',
            //'scriptUrl' => '',
            //'baseUrl' => '/',
            //'hostInfo' => 'http://www.yourhost.com.au',
            //'routeParam' => 'r',
            'ruleConfig' => [
                'class' => 'yii\web\UrlRule'
            ],
            'rules' => array(
                [
                    'pattern' => 'gii',
                    'route' => 'gii',
                    'suffix' => '',
                ],
                [
                    'pattern' => '/<controller:\w+>/<action:\w+>',
                    'route' => 'gii/<controller>/<action>',
                    'suffix' => '',
                ],
                '<controller:\w+>/<id:\d+>' => '<controller>/view',
                '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
                '<controller:\w+>/<action:\w+>' => '<controller>/<action>', 
            ),
        ],

        ... ,
    ],
];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.