bogddan / redirector
A comprehensive Laravel package for managing redirects with ease.
Installs: 1 868
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 9
pkg:composer/bogddan/redirector
Requires
- php: ^8.2
- illuminate/contracts: ^10.0
- illuminate/database: ^10.0
- illuminate/support: ^10.0
Requires (Dev)
- orchestra/testbench: ^8.5
- phpunit/phpunit: ^10.0
- roave/security-advisories: dev-latest
This package is auto-updated.
Last update: 2025-10-15 16:51:55 UTC
README
Nested redirects for Laravel
Overview
This package allows you to create simple or multiple nested redirects for your Laravel applications.
This package can be useful from an SEO perspective, when in your application, you have URLs that have the potential of being modified.
Example of the dynamic redirecting logic:
- 
Let's assume you have an URL called /original
- 
You create a redirect from /originalto/modifiedAccessing /originalwill redirect to/modified
- 
You create another redirect from /modifiedto/modified-againAccessing /modifiedwill redirect to/modified-againAND
 Accessoing/originalwill redirect to/modified-again
- 
You create another redirect from /modified-againto/modified-yet-againAccessing /modified-againwill redirect to/modified-yet-againAND
 Accessing/modifiedwill redirect to/modified-yet-againAND
 Accessing/originalwill redirect to/modified-yet-again
- 
You create another redirect from modified-yet-againto/originalAccessing /modified-yet-againwill redirect to/originalAND
 Accessing/modified-againwill redirect to/originalAND
 Accessing/modifiedwill redirect to/original
Installation
Install the package via Composer:
composer require Bogddan/redirector
Publish the config file with:
php artisan vendor:publish --provider="Bogddan\Redirects\ServiceProvider" --tag="config"
Publish the migration file with:
php artisan vendor:publish --provider="Bogddan\Redirects\ServiceProvider" --tag="migrations"
After the migration has been published you can create the redirects table by running:
php artisan migrate
Usage
Add the middleware
In order for the redirecting functionality to actually happen, you need to add
the Bogddan\Redirects\Middleware\RedirectRequests middleware.
Go to App\Http\Kernel and add the Bogddan\Redirects\Middleware\RedirectRequests middleware in your $middlewareGroups groups of choice.
/** * The application's route middleware groups. * * @var array */ protected $middlewareGroups = [ 'web' => [ ... \Bogddan\Redirects\Middleware\RedirectRequests::class,
Creating redirects
You should never use the Bogddan\Redirects\Models\Redirect directly, as this is the default concrete implementation for the Bogddan\Redirects\Contracts\RedirectModelContract.
Using the Bogddan\Redirects\Models\Redirect model class directly will prevent you from being able to extend the model's capabilities.
You can create redirects that will be stored inside the redirects table like this:
app('redirect.model')->create([ 'old_url' => '/your-old-url', 'new_url' => '/your-new-url', 'status' => 301 ]);
To see how you can extend the Bogddan\Redirects\Models\Redirect model's capabilities, please read the comments from /config/redirects.php -> redirect_model
Credits
Security
If you discover any security related issues, please email Bogddan@tukan.hu instead of using the issue tracker.
License
The MIT License (MIT). Please see LICENSE for more information.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.