mrssoft / yii2-url-redirect
Extension for redirection from old url to new one
Installs: 11
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 0
Type:yii2-extension
Requires
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2024-12-08 16:39:10 UTC
README
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');