F
F
Fridary2018-06-03 22:32:01
Yii
Fridary, 2018-06-03 22:32:01

Yii2: how to redirect config settings controller url?

'components' => [
    'urlManager' => [
        'baseUrl' => '',
        'enablePrettyUrl' => true,
        'showScriptName' => false,
        'rules' => [
            'search' => 'site/index',

            ...
        ],
    ...

On the Yii2 site, if you go to site.com/search-- it works. If you go to site.com/site/indexworks and shows the same content. How to fix it with auto redirect to config settings and parameters? ( site.com/site/index?param=1-> site.com/search?param=1)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kim, 2018-06-04
@kimono

Delete it altogether actionIndexin this case:

class SiteController extends Controller
{
  public $defaultAction = 'search';
  
  public function actionSearch() { ... }
}

'rules' => [
  'search' => 'site/search',
  ...
],

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question