rekurzia/yii2-redirect

一个简单的应用类,在处理请求之前尝试重定向到指定的路由之一。

v1.0.0 2016-01-31 21:45 UTC

This package is not auto-updated.

Last update: 2024-09-20 10:37:52 UTC


README

Latest Stable Version License

自定义应用类,在处理请求之前尝试重定向到指定的路由之一。

如果你移动了网站但忘记正确设置重定向,并收到了许多 404 Not Found 错误,这将很有用。

重定向通过标准的 \yii\helpers\Url::to() 函数进行,因此它们将是 302 Found 重定向。

安装

使用 Composer

composer require rekurzia/yii2-redirect

使用方法

更改你的入口脚本(index.php)以使用此类

(new Rekurzia\redirect\Application($config))->run();

并通过 redirectRoutes 选项添加新的路由

$config['redirectRoutes'] = [
    'some/route' => ['/site/index'],
    'another/route' => ['/site/index', 'page' => 'another'],
    'some/route?a=b&c=d' => ['/site/index', 'page' => 'abcd'],
    'outside/route' => 'https://yiiframework.cn',
];

许可证

MIT。请参阅 LICENSE 文件。