skip to Main Content

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


  1. 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

    Login or Signup to reply.
  2. Look at my example.

    First config urlManager in config.php in ‘app/config’ folder. In my case look like:

     'components' => [
        ...
        'urlManager' => [
                    'enablePrettyUrl' => true,
                    'showScriptName' => false,
                    'rules' => [
                        ''=>'home/index',
                        '<slugm>-<id:d+>-' => 'home/view',
    
                    ],
                ],
        .
        ...
    ],
    

    and create link as fallow:

    Url::to(['/home/view', 'id' => $model->home_id, 'slugm' =>$model->title_sr_latn])
    

    and finaly url look like:

    https://primer.izrada-sajta.rs/usluge-izrade-sajtova-1-

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search