An easy solution to handle redirects in your Laravel application
aw-studio/laravel-redirects is a Laravel package for an easy solution to handle redirects in your laravel application.
It currently has 0 GitHub stars and 4.818 downloads on Packagist (latest version v0.8).
Install it with composer require aw-studio/laravel-redirects.
Discover more Laravel packages by aw-studio
or browse all Laravel packages to compare alternatives.
Last updated
This package provides an easy way to create and manage redirects in your Laravel application.
Install the package via Composer:
composer require aw-studio/laravel-redirects
Publish the packages migrations and config:
php artisan vendor:publish --provider="AwStudio\Redirects\RedirectsServiceProvider"
Run the migration
php artisan migrate
Add AwStudio\Redirects\Middleware\RedirectRoutesMiddleware to /app/Http/Kernel.php:
class Kernel extends HttpKernel
{
protected $middleware = [
...
\AwStudio\Redirects\Middleware\RedirectRoutesMiddleware::class,
],
}
The provided Redirect model stores the following attributes:
With this you may create redirects like this:
app('redirect.model')->create([
'from_url' => '/old',
'to_url' => '/new',
'http_status_code' => 301
]);
If you need to configure some (static) redirects you may do so in the config/redirects.php.
'redirects' => [
'/{any}' => '/en/{any}',
],
By default every redirect from the configuration file is handled as a 301.
You may however overwrite it like this:
'redirects' => [
'/old' => ['/temporary-new', 302],
],
Both, config and database redirects, support Laravel route parameters:
'redirects' => [
'/blog/{post}' => '/news/{post}',
]
//
app('redirect.model')->create([
'from_url' => 'blog/{post}',
'to_url' => 'news/{post}',
]);
This package is inspired by and based on the discontinued Neurony/laravel-redirects package and also takes inspiration from spatie/laravel-missing-page-redirector.