D
D
Dmitry2018-03-01 18:33:30
Yii
Dmitry, 2018-03-01 18:33:30

Is it possible to remove id from query string?

Good evening.
There is a task to bring the links on the site in a more or less decent form.
Initially links were like this

"site.ru/car/show?region=region_name&city=city_name&mark=mark_name&model=model_name&id=23364"

Required to remove the names of the controller, action and id from the address bar.
I completed part of the task.
Registered rules in UrlManager, links became more readable now.
"site.ru/region_name/city_name/mark_name/model_name/23364"

But the customer wants the id to be absent too, that is, the link should look like this in the address bar
"site.ru/region_name/city_name/mark_name/model_name"

He says that it will be better for seo.
Tell me, how can I remove the id from the address, but so that the id is still transmitted to the server?
Can this be done using standard urlManager tools?
p.s. urlManager
() rules
'<region:[\w\-]+>/<city:[\w\-]+>/<mark:[\w\-]+>/<model:[\w\-]+>/<id:\d+>' => 'car/show',
'<mark-name:[\w\-]+>/<model-name:[\w+\-]+>/<model:[\w\-]+>' => 'car/search-by-mark',
'<mark-name:[\w\-]+>/<mark:[\d]+>' => 'car/search-by-mark',
'<region-name:[\w\-]+>/<region:\d+>' => 'car/search-by-region',
'<region-name:[\w\-]+>/<city-name:[\w\-]+>/<region:\d+>/<city:\d+>' => 'car/search-by-city',
'<city-name:[\w\-]+>/<city:\d+>' => 'car/search-by-city',
'<mark-name:[\w\-]+>/<region:\d+>/<city:\d+>' => 'car/search-by-region-city-mark',
'<mark-name:[\w\-]+>/<model-name:[\w+\-]+>/<region:\d+>/<city:\d+>' => 'car/search-by-region-city-mark-model',

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2018-03-01
@slo_nik

It all depends on whether it is possible to uniquely identify the desired record by the parameters passed in the request. If possible, then you should write your own URL-rule that will take the passed parameters and, based on them, determine the record ID. But you should take care of caching this case. such a rule will be quite complicated

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question