aw-studio/laravel-redirects

An easy solution to handle redirects in your Laravel application
4,838
Install
composer require aw-studio/laravel-redirects
Latest Version:v0.8
PHP:^7.4|^8.0|^8.1|^8.2|^8.3
Laravel:8 – 12
License:MIT
Last Updated:Apr 14, 2025
Links: GitHub  ·  Packagist
Maintainer: jannescb

Laravel redirects

This package provides an easy way to create and manage redirects in your Laravel application.

Installation

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,
    ],
}

Usage

Using database redirects

The provided Redirect model stores the following attributes:

  • from_url
  • to_url
  • http_status_code (default 301)
  • active (default true)

With this you may create redirects like this:

app('redirect.model')->create([
    'from_url' => '/old',
    'to_url' => '/new',
    'http_status_code' => 301
]);

Using config redirects

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],
],

Using URL parameters

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}',
]);

Credits

This package is inspired by and based on the discontinued Neurony/laravel-redirects package and also takes inspiration from spatie/laravel-missing-page-redirector.

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

641,106,524 9,700
laravel/framework

The Laravel Framework.

593,882,149 34,959
laravel/tinker

Powerful REPL for the Laravel framework.

502,645,077 7,441
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

418,291,778 609
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

399,241,428 4,660

Version History

Version Released PHP Laravel License
v0.8 ^7.4|^8.0|^8.1|^8.2|^8.3 ^8.0|^9.0|^10.0|^11.0|^12.0 MIT
v0.7 ^7.4|^8.0|^8.1|^8.2 ^8.0|^9.0|^10.0|^11.0 MIT
v0.6 ^7.4|^8.0|^8.1 ^8.0|^9.0|^10.0 MIT
v0.5 ^7.4|^8.0|^8.1 ^8.0|^9.0|^10.0 MIT
v0.4 ^7.4|^8.0|^8.1 ^8.0|^9.0|^10.0 MIT