yiiyii-url-manager

Remove controller and action from url yii


I want to hide controller and action name from url and only slug will show.E.g http://localhost/test-project/frontend/web/test-condition and "test-condition" is slug.I want to manage this from urlManager in my config/main.php


Solution

  • 'urlManager' => [
                'class' => 'yii\web\UrlManager',
                // Disable index.php
                'showScriptName' => false,
                // Disable r= routes
                'enablePrettyUrl' => true,
                'rules' => array(
                    ....
                    '<slug:[a-zA-Z0-9_ -]+>-consult' => 'CONTROLLER NAME/ACTION',
                ),
            ],