pendalf89 / yii2-redirect
Component for convenient URL redirects in Yii2.
Installs: 14
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- yiisoft/yii2: ^2.0
This package is auto-updated.
Last update: 2024-11-22 08:22:28 UTC
README
Component for convenient URL redirects in Yii2.
Features
- All redirects are stored in the DB
- Fast speed
- Easy installation and usage
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require pendalf89/yii2-redirect
or add
"pendalf89/yii2-redirect": "^1.0.0"
to the require section of your composer.json
file.
Create table in your database (MySQL, Postgres etc.)
CREATE TABLE `redirect` ( `source` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, `target` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, `created_at` datetime NOT NULL, PRIMARY KEY (`source`) USING BTREE, KEY `created_at` (`created_at`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
Configuration:
'on beforeRequest' => function() { Yii::$app->redirect->run(); }, 'components' => [ 'redirect' => 'pendalf89\redirect\Redirect', ],
Installation done.
Usage
Just add your urls to DB:
Yii::$app->redirect->add('https://example.com/from/', 'https://example.com/to/');
After that the redirects will work.