i want to rewrite my URLs from
/view?id=100
to
/view/100-article-title
But the site already has several thousand search pages. As far as I know, such a change can be bad for SEO. Is there a way to keep the old URLs working when switching to the new routing.
*I am creating links as follows:
Url::to(['view', 'id' => $item->id])
Is it possible to create links further through ID?
2
Answers
you can create getLink() function on your model and use it on. Then, when function runs you can check id if id <= 100 then return Url::to([‘view’, ‘id’ => $item->id]) else return Url::to([‘view’, ‘id’ => $item->id, ‘slug’ => $this->slug])
And add route with slug on your main.php
Look at my example.
First config urlManager in config.php in ‘app/config’ folder. In my case look like:
and create link as fallow:
and finaly url look like:
https://primer.izrada-sajta.rs/usluge-izrade-sajtova-1-