Manage redirects based on referers. You can add start and end dates so a referer can redirect to different url's in different time periods.
You can install the package via composer:
composer require appstract/laravel-referer-redirector
By running php artisan vendor:publish --provider="Appstract\RefererRedirector\RefererRedirectorServiceProvider" in your project all files for this package will be published. The file that will be published is a migration. A middleware will be registered.
Run the migration:
php artisan migrate
You need to add a middleware to handle the requests.
Add it to single routes:
Route::get('welcome', function () {
//
})->middleware('redirect-referer');
Add it to route groups:
Route::group(['middleware' => ['redirect-referer']], function () {
//
});
Or add it as global middleware:
protected $middleware = [
...
\Appstract\RefererRedirector\Middleware\RedirectReferer::class,
...
];
You can add a new redirect based on referer:
php artisan referer:make {referer} {redirect} {--start=} {--end=}
This will lead you through the needed steps.
Remove referer-redirect based on referer or ID:
php artisan referer:remove {referer}
List all referer-redirects:
php artisan referer:list
If you're going to add referer-redirects manually to the database, keep the following in mind:
- referer_url: add without http://, https://, ending /
- redirect_url: the package will make a redirect(redirect_url), so make sure this url exists
- start_date: datetime (Carbon)
- end_date: datetime (Carbon)
$ composer test
Contributions are welcome, thanks to y'all :)
Appstract is a small team from The Netherlands. We create (open source) tools for webdevelopment and write about related subjects on Medium. You can follow us on Twitter, buy us a beer or support us on Patreon.
The MIT License (MIT). Please see License File for more information.