Answer the question
In order to leave comments, you need to log in
How to compose a regular expression in Yii2?
There is an address: sitename.ru/category/abc?letter=С
What regular expression is needed to be like this: sitename.ru/category/abc/С
The last parameter changes, these are letters of the alphabet.
And also, there is another address: sitename.ru/category/abc?letter=C&page=2
What regular expression is needed to be like this:sitename.ru/category/abc/C/page/2
Answer the question
In order to leave comments, you need to log in
Use Named Parameters in URL Rules
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
// порядок следования правил важен для корректного формирования ссылок
'category/abc/<letter:\w+>/page/<page:\d+>' => 'category/abc',
'category/abc/<letter:\w+>' => 'category/abc',
]
],
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question