如何在yi1中进行URL路由设置


How to do URL routing settings in Yii1?

我在Yii中的url有问题。当我像这样输入URL

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

它不会打开那个页面,而是重定向到主页。

但是当我像这样输入url,

http://localhost/yii_project/index.php?r = gii/默认登录

it open successfully.

我不想使用index.php?我想显示它index。php/gii/..

将/protected/config/main.php更改为

'urlManager' => array(
        'urlFormat' => 'path',
        'showScriptName' => false, 
        'rules' => array(
            'search/<action:'w+>/'=>'dashboard/search/<action>',
            'view/<action:'w+>/'=>'dashboard/view/<action>',
        ),
在yii中隐藏index.php

您使用的是Yii1还是Yii2 ?

对于Yii2 Basic App(当前版本),打开@app/config/web.php并添加以下代码:

这将导致如下结果:http://localhost/yii_project/gii/default/login

如果您想包含index.php,那么更改一行为'showScriptName' => true,返回(…,'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>', 
            ),
        ],
        ... ,
    ],
];