Behzad Hassani
Behzad Hassani

Reputation: 2139

use static url in url routing yii2

I have an old website, now I have written it with new version of yii framework and I want change the urls, but because of SEO problems I want to keep my old urls. Now when the user enters www.mysite.pre/car/details/10908 I want application renders www.mysite.pre/site/show_detail/10908 how could I handle it in yii2 Routing?

Upvotes: 0

Views: 426

Answers (1)

Bizley
Bizley

Reputation: 18021

Assuming you have got this action in your SiteController class

public function actionShow_detail($id) {}

Add this in your configuration file:

// ...
'components' => [
    // ...
    'urlManager' => [
        'enablePrettyUrl' => true,
        'showScriptName'  => false,
        'rules'           => [
            // ...
            'car/details/<id:\d+>' => 'site/show_detail',
        ],
    ],
],

More details and information about Yii 2 routing can be found in "Routing and URL Creation" section of The Definitive Guide to Yii 2.0.

Upvotes: 1

Related Questions