Yii - Hiding module name in URL

后端 未结 2 1890
闹比i
闹比i 2020-12-12 04:47

My present URL structure is as below:

http://www.mydomain.com/module/controller/action

I need to hide the module section of the URL. Is there any way this ca

2条回答
  •  南笙
    南笙 (楼主)
    2020-12-12 05:47

    To point the URL http://www.mydomain.com/customer/login to the module, in you config (protected/config/main.php) under urlManager:

    'urlManager'=>array(
            'urlFormat'=>'path',
            'showScriptName' => false,
            'rules'=>array(
                'customer/login' => 'module/controller/action',
    
                '/'=>'/view',
                '//'=>'/',
                '/'=>'/',
            ),
        ),
    

    To make any controller action go to module/controller/action (as discussed below) you can use:

    '/'=>'module/controller/action',
    

    or

    '/'=>'module//',
    

    Depending on whether the controller/action part of the value (on the right hand side of the =>) is a set value, or a variable.

    So if you want any controller/action to go to the exact url module/controller/action, you would use the first example. For example if you want the controller/action site/test to go to module/controller/action, you would use the first example above

    If you want any controller/action to go to a dynamic controller/action you use the second. For example, if you want the controller/action site/test to go to module/site/test, you would use the second example above

    This new rule must be above the 3 default Yii rules as they are read and top to bottom and match the first rule it finds only

提交回复
热议问题