hiraeth / middleware-browser-redirect
Redirect browsers / versions to alternative URLs
Installs: 4 981
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:opus-package
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-10-14 18:40:01 UTC
README
This is a PSR-15 middleware that can be configured with a series of rules to detect specific browsers, versions, and request paths and redirect them to an alternate URL.
Basic Usage
// // 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 Integration
- Package configuration and middleware configuration will be copied on install
- Additional rules can be added to any config as an array of objects:
[browser] rules = [ { "target": "/.*", "browser": "IE", "version": "<10", "redirect": "https://getfirefox.com" } ]