Answer the question
In order to leave comments, you need to log in
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"
"site.ru/region_name/city_name/mark_name/model_name/23364"
"site.ru/region_name/city_name/mark_name/model_name"
'<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
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 questionAsk a Question
731 491 924 answers to any question