Custom Application class which tries to redirect to one of specified routes before handling request.
It's useful if you moved website and forgot to set redirects properly and receiving many 404 Not Found
errors.
Redirects go through standard \yii\helpers\Url::to()
function, so they'll be 302 Found
redirects.
Using Composer:
composer require rekurzia/yii2-redirect
Change your entry script (index.php
) to use this class:
(new Rekurzia\redirect\Application($config))->run();
And add new routes through redirectRoutes
option:
$config['redirectRoutes'] = [
'some/route' => ['/site/index'],
'another/route' => ['/site/index', 'page' => 'another'],
'some/route?a=b&c=d' => ['/site/index', 'page' => 'abcd'],
'outside/route' => 'http://www.yiiframework.com',
];
MIT. See LICENSE file.