PHPackages                             esign/laravel-redirects - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. esign/laravel-redirects

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

esign/laravel-redirects
=======================

A laravel package to control redirects from the database or other sources.

2.2.0(2mo ago)16.5k↓44.1%1MITPHPPHP ^8.1CI passing

Since Feb 9Pushed 2mo ago4 watchersCompare

[ Source](https://github.com/esign/laravel-redirects)[ Packagist](https://packagist.org/packages/esign/laravel-redirects)[ Docs](https://github.com/esign/laravel-redirects)[ RSS](/packages/esign-laravel-redirects/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (12)Versions (11)Used By (0)

Control redirects from the database
===================================

[](#control-redirects-from-the-database)

[![Latest Version on Packagist](https://camo.githubusercontent.com/a64d6babbaa0398b002888981e4163cb4bccc6c045aac02949ba9fdedd0fcbe6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f657369676e2f6c61726176656c2d7265646972656374732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/esign/laravel-redirects)[![Total Downloads](https://camo.githubusercontent.com/27e73832aa9d9ad8d9413119dbafc9cacdc918a8ba95af92832ecd38dbafac47/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f657369676e2f6c61726176656c2d7265646972656374732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/esign/laravel-redirects)[![GitHub Actions](https://github.com/esign/laravel-redirects/actions/workflows/run-tests.yml/badge.svg)](https://github.com/esign/laravel-redirects/actions/workflows/run-tests.yml/badge.svg)

This package provides an easy way to load redirects from the database instead of defining them in your route files. By default the package will only load your redirects when the original request results in a 404.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require esign/laravel-redirects
```

The package will automatically register a service provider.

For the redirects to be active you must register the `Esign\Redirects\Http\Middleware\CheckForRedirects` middleware.

**Laravel 11+**

```
// bootstrap/app.php

->withMiddleware(function (Middleware $middleware) {
     $middleware->append(Esign\Redirects\Http\Middleware\CheckForRedirects::class);
})
```

**Older versions (up to Laravel 10)**

```
// app/Http/Kernel.php

protected $middleware = [
    ...
    Esign\Redirects\Http\Middleware\CheckForRedirects::class,
];
```

This package comes with a migration to store your redirects. In case you want to modify this migration you may publish it using:

```
php artisan vendor:publish --provider="Esign\Redirects\RedirectsServiceProvider" --tag="migrations"
```

Next up, you can publish the configuration file:

```
php artisan vendor:publish --provider="Esign\Redirects\RedirectsServiceProvider" --tag="config"
```

The config file will be published as `config/redirects.php` with the following content:

```
return [
    /**
     * This is the model used by the DatabaseRedirector.
     * It should implement the RedirectContract interface and extend the Model class.
     */
    'redirect_model' => Esign\Redirects\Models\Redirect::class,

    /**
     * This class provides the redicect url's to the CheckForRedirects middleware.
     * It should implement the RedirectorContract interface.
     */
    'redirector' => Esign\Redirects\Redirectors\DatabaseRedirector::class,

    'cache' => [
        /**
         * The key that will be used to cache the redirects.
         */
        'key' => 'esign.laravel-redirects.redirects',

        /**
         * The duration for which database redirects will be cached.
         */
        'ttl' => \DateInterval::createFromDateString('24 hours'),

        /**
         * The cache store to be used for database redirects.
         * Use null to utilize the default cache store from the cache.php config file.
         * To disable caching, you can use the 'array' store.
         */
        'store' => null,
    ],
];
```

Usage
-----

[](#usage)

Defining redirects in the database is pretty straight forward:

```
Redirect::create([
    'old_url' => 'my-old-url',
    'new_url' => 'my-new-url',
]);
```

It's also possible to define route parameters just like the way you're used to in Laravel:

```
Redirect::create([
    'old_url' => 'my-old-url/{slug}',
    'new_url' => 'my-new-url/{slug}',
]);
```

*When using route parameters, the following parameters are reserved by Laravel and cannot be used: `destination` and `status`.*

You may even swap the order of the route parameters

```
Redirect::create([
    'old_url' => 'my-old-url/{slug}/{year}',
    'new_url' => 'my-new-url/{year}/{slug}',
]);
```

By default a `302` status will be used, but you can also supply a custom status code

```
Redirect::create([
    'old_url' => 'my-old-url/{slug}/{year}',
    'new_url' => 'my-new-url/{year}/{slug}',
    'status_code' => 301,
]);
```

It's also possible to redirect to external urls

```
Redirect::create([
    'old_url' => 'my-old-url',
    'new_url' => 'https://www.esign.eu',
]);
```

This package also allows you to define [constraints](https://laravel.com/docs/routing#parameters-regular-expression-constraints) for your routes:

```
Redirect::create([
    'old_url' => 'user/{id}',
    'new_url' => 'users/{id}',
    'constraints' => ['id' => '[0-9]+'],
]);

Redirect::create([
    'old_url' => 'nl/{any?}',
    'new_url' => 'nl-be/{any?}',
    'constraints' => ['any' => '.*'],
]);
```

This package also ships with a `DatabaseWildcardRedirector`, which allows you to define redirects by using `*` as a wildcard. This will automatically apply a constraint to match any trailing url segments:

```
Redirect::create([
    'old_url' => 'my-old-url/*',
    'new_url' => 'my-new-url/*',
]);
```

### Caching redirects

[](#caching-redirects)

By default, this package ensures efficient performance by caching your database redirects for 24 hours. This caching mechanism uses the default cache driver that you have configured within your Laravel application.

If you wish to modify the cache duration or switch to a different cache store, please refer to the cache settings within the [configuration file](/config/redirects.php).

### Clearing the redirects cache

[](#clearing-the-redirects-cache)

The redirects cache is automatically maintained when you interact with the `Esign\Redirects\Models\Redirect` model. However, if you make changes outside of these operations, you need to manually clear the cache:

```
php artisan redirects:clear-cache
```

Testing
-------

[](#testing)

```
composer test
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance87

Actively maintained with recent releases

Popularity26

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 90.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~249 days

Recently: every ~278 days

Total

7

Last Release

62d ago

Major Versions

1.2.0 → 2.0.02024-08-05

PHP version history (2 changes)1.0.0PHP ^8.0

2.1.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/4599d7a8f6fdb63dd04305a49ae5ec9700b7a6eacdbe3a54f89584d75e34503f?d=identicon)[esign](/maintainers/esign)

---

Top Contributors

[![jordyvanderhaegen](https://avatars.githubusercontent.com/u/24370626?v=4)](https://github.com/jordyvanderhaegen "jordyvanderhaegen (38 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (3 commits)")[![thdebay](https://avatars.githubusercontent.com/u/1422621?v=4)](https://github.com/thdebay "thdebay (1 commits)")

---

Tags

laravelredirectsesign

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/esign-laravel-redirects/health.svg)

```
[![Health](https://phpackages.com/badges/esign-laravel-redirects/health.svg)](https://phpackages.com/packages/esign-laravel-redirects)
```

###  Alternatives

[yajra/laravel-datatables-oracle

jQuery DataTables API for Laravel

4.9k33.8M339](/packages/yajra-laravel-datatables-oracle)[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[spatie/laravel-enum

Laravel Enum support

3655.4M31](/packages/spatie-laravel-enum)[psalm/plugin-laravel

Psalm plugin for Laravel

3274.9M308](/packages/psalm-plugin-laravel)[datomatic/nova-enum-field

A Laravel Nova PHP 8.1 enum field with filters

20134.2k](/packages/datomatic-nova-enum-field)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
