Skip to content

mrs2000/yii2-redirect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

yii2-url-redirect

Extension for redirection from old url to new one.

Configure

Add to config:

    'components' => [
        ...
        'redirect' => [
            'class' => 'mrssoft\redirect\UrlRedirect',
            'tableName' => '{{%redirect}}', // Table name
            'db' => 'db', // DB connection component
            'code' => 302, // Redirect status code
        ],
        'response' => [
            'as urlRedirect' => [
                'class' => 'mrssoft\redirect\UrlBehavior',
                'redirect' => 'redirect' // UrlRedirect component
            ]
        ],
        ...
    ]

Add the table to the database:

    CREATE TABLE `redirect` (
        `old_url` VARCHAR(255) NOT NULL,
        `new_url` VARCHAR(255) NOT NULL,
        `date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
        PRIMARY KEY (`old_url`)
    )
    ENGINE=InnoDB

Usage

Add a link to the redirect database:

    Yii::$app->redirect->add('/old/url/', '/new/url');

Clear old links:

    Yii::$app->redirect->clear('-3 month');

About

Extension for redirection from old url to new one.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages