yii2yii2-advanced-appyii2-user

RBAC Routes add default route of module to all the routes of project?


If I add this configuration of the cms module to the config file

'cms' => [
        'class' => 'yii2mod\cms\Module',
        'controllerNamespace' => 'backend\controllers',
        'defaultRoute' => '',
        'froalaEditorOptions' => [
            'clientOptions' => [
                'heightMin' => 300,
                'theme' => 'dark',
                'imageUploadURL' => 'upload-image',
                'imageManagerDeleteURL' => 'delete-image',
                'imageManagerDeleteMethod' => 'POST',
                'imageManagerLoadURL' => 'images'
            ],
            'excludedPlugins' => [
                'file',
                'emoticons'
            ]
        ],
        'enableMarkdown' => false
]

It adds the default route of this module to all the routes like this /cms/site/login /cms/site/index /cms/site/error. Why this is happening and how i can remove this?


Solution

  • If you want to remove the /cms module prefix by default, you can add a global route to backend/config/main.php(If you use advanced templates): '<controller:[\w-]+>/<action:[\w-]+>' =>'cms/<controller>/<action>'.

    for example:

    // backend/config/main.php
    return [
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
                '<controller:[\w-]+>/<action:[\w-]+>' =>'cms/<controller>/<action>'
            ],
        ],
    ];
    

    Access in your bowser: www.xxx.com/site/index, it is forwarded to: /cms/site/index