samsonasik/expressive-redirect-handler
最新稳定版本:2.0.0
Composer 安装命令:
composer require samsonasik/expressive-redirect-handler
包简介
Expressive middleware for URL Redirect handling
关键字:
README 文档
README
This is README for version ^2.0 which only support Mezzio version 3 with php ^7.1.
For version ^1.0, , you can read at version 1.* readme which support ZF Expressive version 3 with php ^7.1.
For version 0.*, you can read at version 0.* readme which still ZF Expressive version 1 and 2 with php ^5.6|^7.0 support.
ExpressiveRedirectHandler is a package that contains Mezzio middleware for handling redirect that fit with mezzio-skeleton for following conditions:
- When the given url to
RedirectResponseis not registered in routing config
For example, we use RedirectResponse instance in our Middleware:
use Laminas\Diactoros\Response\RedirectResponse; // ... $redirect = '/foo'; // may be a variable from GET return new RedirectResponse($redirect);
if the passed $redirect as url is a valid and registered in the routes, it uses default RedirectResponse implementation, otherwise, it will redirect to default default_url registered in config/autoload/expressive-redirect-handler.local.php:
For example, we define:
<?php return [ 'expressive-redirect-handler' => [ 'allow_not_routed_url' => false, 'default_url' => '/', 'options' => [ 'exclude_urls' => [ // 'https://www.github.com/samsonasik/ExpressiveRedirectHandler', ], // to allow excluded urls to always be redirected 'exclude_hosts' => [ // 'www.github.com' ], ], ], // ... ];
It means, we can't allow to make redirect to outside registered routes, whenever found un-registered url in routes, then we will be redirected to default_url. It also disable redirect to self, so you can't redirect to self.
For specific urls that exceptional ( allowed to be redirected even not registered in routes), you can register at exclude_urls/exclude_hosts options.
if you define exclude_urls/exclude_hosts options, which one of them is your own current url/host/domain, its your risk to still get "infinite" redirection loops. so, make sure exclude_urls/exclude_hosts is not your current own.
- When you want to redirect to specific url based on header status code
<?php return [ 'expressive-redirect-handler' => [ 'allow_not_routed_url' => false, 'default_url' => '/', 'header_handler' => [ 'enable' => true, // enable it! 'headers' => [ 401 => '/login', 503 => '/maintenance', ], ], ], // ... ];
Based on the configuration above, when header status code is 401 or 503, it will be redirected to its paired value.
Installation
- Require via composer
composer require samsonasik/expressive-redirect-handler
-
Copy
vendor/samsonasik/expressive-redirect-handler/config/expressive-redirect-handler.local.php.disttoconfig/autoload/expressive-redirect-handler.local.phpand modify on our needs. -
Open
config/pipeline.phpand add:
$app->pipe(ExpressiveRedirectHandler\Middleware\RedirectHandlerAction::class);
at the very first pipeline records.
Contributing
Contributions are very welcome. Please read CONTRIBUTING.md
Credit
统计信息
- 总下载量: 50
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-10-25