hiraeth / middleware-browser-redirect
重定向浏览器/版本到备用URL
2.0.0
2022-11-04 21:45 UTC
Requires
- hiraeth/app: ^2.0
- hiraeth/middleware-imp: ^2.0
- sinergi/browser-detector: ^6.1
Requires (Dev)
- hiraeth/diactoros: ^2.0
- hiraeth/middleland: ^2.0
- phpstan/phpstan: ^1.0
This package is auto-updated.
Last update: 2024-09-14 18:26:23 UTC
README
这是一个PSR-15中间件,可以通过一系列规则配置来检测特定的浏览器、版本和请求路径,并将它们重定向到备用URL。
基本用法
// // The factory must be an actual instance of a response factory, the PSR interface here is // used as a stand in for any particular PSR compatible implementation. // $factory = new Psr\Http\Message\ResponseFactoryInterface(); $browser = new Sinergi\BrowserDetector\Browser(); $redirect = new BrowserRedirect($browser, $factory); $redirect->addRule([ 'target' => '/.*', 'browser' => 'IE', 'version' => '<10', 'redirect' => 'https://getfirefox.com' ]); // // This will actually be executed by your middleware stack, so you probably don't need to do this // yourself. // $response = $redirect->process($request, $handler);
Hiraeth集成
- 安装时,将复制包配置和中间件配置
- 可以将额外的规则添加到任何配置中,作为对象数组
[browser] rules = [ { "target": "/.*", "browser": "IE", "version": "<10", "redirect": "https://getfirefox.com" } ]