Answer the question
In order to leave comments, you need to log in
How to clean up URL in config file in YII2?
Good afternoon, please teach
YII2/config/web.php
//блок с ЧПУ
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'news/<action>'=>'class1/<action>',
'pages/<action>'=>'class2/<action>',
'webs/<action>'=>'class3/<action>',
'<get1>/<get2>/<get3>/<get4>/<get5>'=>'site/index',
'<get1>/<get2>/<get3>/<get4>'=>'site/index',
'<get1>/<get2>/<get3>'=>'site/index',
'<get1>/<get2>'=>'site/index',
'<get1>'=>'site/index',
''=>'site/index',//главная
],
],
Answer the question
In order to leave comments, you need to log in
It is better to implement a url-rule that will form / parse the url according to the parameters you need
If there are not infinitely many parameters and you don’t want to create your own class from UrlRule, then you can do this:
'rules' => [
'news/<action>'=>'class1/<action>',
'pages/<action>'=>'class2/<action>',
'webs/<action>'=>'class3/<action>',
[
'pattern' => '<get1>/<get2>/<get3>/<get4>/<get5>',
'route' => 'site/index',
'defaults' => ['get1' => null, 'get2' => null, 'get3' => null, 'get4' => null, 'get5' => null],
],
],
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question