PHPackages                             vkovic/laravel-db-redirector - 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. [Database &amp; ORM](/categories/database)
4. /
5. vkovic/laravel-db-redirector

ActiveLibrary[Database &amp; ORM](/categories/database)

vkovic/laravel-db-redirector
============================

Persist and manage HTTP redirections in Laravel

v1.0.2(6y ago)141411[1 issues](https://github.com/vkovic/laravel-db-redirector/issues)1MITPHPPHP ^7.1

Since Dec 5Pushed 6y ago1 watchersCompare

[ Source](https://github.com/vkovic/laravel-db-redirector)[ Packagist](https://packagist.org/packages/vkovic/laravel-db-redirector)[ RSS](/packages/vkovic-laravel-db-redirector/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (4)Versions (4)Used By (1)

Laravel DB redirector
=====================

[](#laravel-db-redirector)

[![Build](https://camo.githubusercontent.com/95b7d5beb1daf9849736587854eeec7afeebe74b297997c62536f99896a9e8f3/68747470733a2f2f7472617669732d63692e6f72672f766b6f7669632f6c61726176656c2d64622d72656469726563746f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/vkovic/laravel-db-redirector)[![Downloads](https://camo.githubusercontent.com/57a19b259a4502dccecfc5da0d6fd12b032e54deadf1ffb50a7c615d11b017b1/68747470733a2f2f706f7365722e707567782e6f72672f766b6f7669632f6c61726176656c2d64622d72656469726563746f722f646f776e6c6f616473)](https://packagist.org/packages/vkovic/laravel-db-redirector)[![Stable](https://camo.githubusercontent.com/d8f214c231b9c2060b05c331c2770e900c0efa79e0989230c77a369542d1867c/68747470733a2f2f706f7365722e707567782e6f72672f766b6f7669632f6c61726176656c2d64622d72656469726563746f722f762f737461626c65)](https://packagist.org/packages/vkovic/laravel-db-redirector)[![License](https://camo.githubusercontent.com/ab1016dfdc58446039812df56b12985d809ce444e21b750e39fbca59cf065ad8/68747470733a2f2f706f7365722e707567782e6f72672f766b6f7669632f6c61726176656c2d64622d72656469726563746f722f6c6963656e7365)](https://packagist.org/packages/vkovic/laravel-db-redirector)

### Manage HTTP redirections in Laravel using database

[](#manage-http-redirections-in-laravel-using-database)

Manage redirects using database rules. Rules are intended to be very similar to Laravel default routes, so syntax is pretty easy to comprehend.

---

Compatibility
-------------

[](#compatibility)

The package is compatible with Laravel versions `5.5`, `5.6`, `5.7` and `5.8` and PHP versions `7.1` and `7.2`

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

[](#installation)

Install the package via composer:

```
composer require vkovic/laravel-db-redirector
```

Database redirector middleware needs to be added to middleware array:

```
// File: app/Http/Kernel.php

// ...

protected $middleware = [
    // ...
    \Vkovic\LaravelDbRedirector\Http\Middleware\DbRedirectorMiddleware::class
];
```

Run migrations to create table which will store redirect rules:

```
php artisan migrate
```

Usage: Simple Examples
----------------------

[](#usage-simple-examples)

Creating a redirect is easy. You just have to add db record via provided RedirectRule model. Default status code for redirections will be 301 (Moved Permanently).

```
use Vkovic\LaravelDbRedirector\Models\RedirectRule;

// ...

RedirectRule::create([
    'origin' => '/one/two',
    'destination' => '/three'
]);
```

You can also specify another redirection status code:

```
RedirectRule::create([
    'origin' => '/one/two',
    'destination' => '/three',
    'status_code' => 307 // Temporary Redirect
]);
```

You may use route parameters just like in native Laravel routes, they'll be passed down the road - from origin to destination:

```
RedirectRule::create([
    'origin' => '/one/{param}',
    'destination' => '/two/{param}'
]);

// If we visit: "/one/foo" we will end up at "two/foo"
```

Optional parameters can also be used:

```
RedirectRule::create([
    'origin' => '/one/{param1?}/{param2?}',
    'destination' => '/four/{param1}/{param2}'
]);

// If we visit: "/one" we'll end up at "/four
// If we visit: "/one/two" we'll end up at "/four/two"
// If we visit: "/one/two/three" we'll end up at "/four/two/three"
```

Chained redirects will also work:

```
RedirectRule::create([
    'origin' => '/one',
    'destination' => '/two'
]);

RedirectRule::create([
    'origin' => '/two',
    'destination' => '/three'
]);

RedirectRule::create([
    'origin' => '/three',
    'destination' => '/four'
]);

// If we visit: "/one" we'll end up at "/four"
```

We also can delete the whole chain at once (3 previous redirect records in this example):

```
RedirectRule::deleteChainedRecursively('/four');
```

Sometimes it's possible that you'll have more than one redirection with the same destination. So it's smart to surround code with try catch block, because exception will be raised in this case:

```
RedirectRule::create(['origin' => '/one/two', 'destination' => '/three/four']);
RedirectRule::create(['origin' => '/three/four', 'destination' => '/five/six']);

// One more with same destination ("/five/six") as the previous one.
RedirectRule::create(['origin' => '/ten/eleven', 'destination' => '/five/six']);

try {
    RedirectRule::deleteChainedRecursively('five/six');
} catch (\Exception $e) {
    // ... handle exception
}
```

Usage: Advanced
---------------

[](#usage-advanced)

What about order of rules execution when given url corresponds to multiple rules. Let's find out in this simple example:

```
RedirectRule::create(['origin' => '/one/{param}/three', 'destination' => '/four']);
RedirectRule::create(['origin' => '/{param}/two/three', 'destination' => '/five']);

// If we visit: "/one/two/three" it corresponds to both of rules above,
// so, where should we end up: "/four" or "/five" ?
// ...
// It does not have anything to do with rule order in our rules table!
```

To solve this problem, we need to agree on simple (and logical) rule prioritizing:

**Priority 1:**Rules without named parameters have top priority:

**Priority 2:**If rule origin have named parameters, those with less named parameters will have higher priority

**Priority 3:**If rule origin have same number of named parameters, those where named parameters are nearer the end of the rule string will have priority

So lets examine our previous case, we have:

- "/one/{param}/three" =&gt; "/four"
- "/{param}/two/three" =&gt; "/five"

In this case both rules have the same number of named params, but in the first rule "{param}" is nearer the end of the rule, so it will have priority and we'll end up at "/four".

---

Contributing
------------

[](#contributing)

If you plan to modify this Laravel package you should run tests that comes with it. Easiest way to accomplish this would be with `Docker`, `docker-compose` and `phpunit`.

First, we need to initialize Docker containers:

```
docker-compose up -d
```

After that, we can run tests and watch the output:

```
docker-compose exec app vendor/bin/phpunit
```

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~129 days

Total

3

Last Release

2456d ago

PHP version history (2 changes)v1.0.0PHP ^7.0

v1.0.2PHP ^7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/af6bef6672c28298c8c200a89e8c076049ef170ebf50cea3cb7eb96c2ee5c105?d=identicon)[vkovic](/maintainers/vkovic)

---

Top Contributors

[![vkovic](https://avatars.githubusercontent.com/u/4613605?v=4)](https://github.com/vkovic "vkovic (5 commits)")

---

Tags

databaselaravelpackageredirectrouterroutinglaraveldatabaseredirect

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/vkovic-laravel-db-redirector/health.svg)

```
[![Health](https://phpackages.com/badges/vkovic-laravel-db-redirector/health.svg)](https://phpackages.com/packages/vkovic-laravel-db-redirector)
```

###  Alternatives

[nunomaduro/laravel-optimize-database

Publishes migrations that make your database production ready.

26123.0k](/packages/nunomaduro-laravel-optimize-database)[hpolthof/laravel-translations-db

A database translations implementation for Laravel 5.

545.8k](/packages/hpolthof-laravel-translations-db)[cubettech/lacassa

Cassandra based query builder for laravel.

358.5k](/packages/cubettech-lacassa)[codengine/laravel-custom-migrations

Custom Migrations for Laravel

131.3k](/packages/codengine-laravel-custom-migrations)

PHPackages © 2026

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