Could not find or correctly form a question. Faced such a problem:

My url: site.ru/module/controller/?handler=action

I want to redirect to site.ru/module/controller/action Tried to specify this in the rules

[ 'pattern' => 'module/controller/<handler:\w+>', 'route' => 'module/controller/<handler>' ] 

Tell me how to write the rule correctly and can I use it in a route?

1 answer 1

backend / config / main.php

frontend / config / main.php in these places you need to write

 'request' => [ 'baseUrl' => '', ], 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ '' => 'site/index', '<action>'=>'site/<action>', ], ], 

This is my fronted

 <?php $params = array_merge( require(__DIR__ . '/../../common/config/params.php'), require(__DIR__ . '/../../common/config/params-local.php'), require(__DIR__ . '/params.php'), require(__DIR__ . '/params-local.php') ); return [ 'id' => 'app-frontend', 'basePath' => dirname(__DIR__), 'bootstrap' => ['log'], 'controllerNamespace' => 'frontend\controllers', 'components' => [ 'request' => [ 'baseUrl' => '', ], 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ '' => 'site/index', '<action>'=>'site/<action>', ], ], 'user' => [ 'identityClass' => 'common\models\User', 'enableAutoLogin' => true, ], 'log' => [ 'traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [ [ 'class' => 'yii\log\FileTarget', 'levels' => ['error', 'warning'], ], ], ], 'errorHandler' => [ 'errorAction' => 'site/error', ], /* 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ ], ], */ ], 'params' => $params, ];