Hello everyone!
I have catalogue with products. Urls for products looks like this domain.com/adv?id=14792
. I want to beautify urls like this domain.com/adv/14792
.
In web.php I tried to like this
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'adv/<id:\d+>' => 'site/adv',
'<alias:[\w-]+>' => 'site/<alias>',
],
],
and there is no result.
I tried another variant in rules block:
'rules' => [
'adv/<id:\d+>' => 'adv',
'<alias:[\w-]+>' => 'site/<alias>',
],
and urls start to look like I want. But on this link I get 404 page.
tri
(tri - Tommy Riboe)
2
What does and there is no result mean?
If no 404 and blank screen you can have some php error.
Did you try whether domain.com/site/adv/14792
works?
You can use the Yii2 debugger to find out which url rule is in effect.
Or is your problem about url creation?
Sorry, I solved my problem by myself. This is my urlmanager module now:
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'adv/<id:\d+>' => 'site/adv',
'<alias:[\w-]+>' => 'site/<alias>',
'<controller:\w+>/<action:\w+>/' => '<controller>/<action>',
],
this construction build url from https://domain.com/adv?id=123456 to https://domain.com/adv/123456.
In view link build with
Html::a($insideEl,Url::to(['adv','id' => $ladvert->id]))
and in siteController action is
actionAdv($id)
Thanx.