tofandel/laravel-redirects is a Laravel package for nested urls redirect logic for laravel.
It currently has 3 GitHub stars and 7.509 downloads on Packagist (latest version v4.3.0).
Install it with composer require tofandel/laravel-redirects.
Discover more Laravel packages by tofandel
or browse all Laravel packages to compare alternatives.
Last updated
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 /original to /modified
Accessing
/originalwill redirect to/modified
You create another redirect from /modified to /modified-again
Accessing
/modifiedwill redirect to/modified-againAND
Accessoing/originalwill redirect to/modified-again
You create another redirect from /modified-again to /modified-yet-again
Accessing
/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-again to /original
Accessing
/modified-yet-againwill redirect to/originalAND
Accessing/modified-againwill redirect to/originalAND
Accessing/modifiedwill redirect to/original
Install the package via Composer:
composer require Tofandel/laravel-redirects
Publish the config file with:
php artisan vendor:publish --provider="Tofandel\Redirects\ServiceProvider" --tag="config"
Publish the migration file with:
php artisan vendor:publish --provider="Tofandel\Redirects\ServiceProvider" --tag="migrations"
After the migration has been published you can create the redirects table by running:
php artisan migrate
In order for the redirecting functionality to actually happen, you need to add the Tofandel\Redirects\Middleware\RedirectRequests middleware.
Go to App\Http\Kernel and add the Tofandel\Redirects\Middleware\RedirectRequests middleware in your $middlewareGroups groups of choice.
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
...
\Tofandel\Redirects\Middleware\RedirectRequests::class,
You should never use the Tofandel\Redirects\Models\Redirect directly, as this is the default concrete implementation for the Tofandel\Redirects\Contracts\RedirectModelContract.
Using the Tofandel\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 Tofandel\Redirects\Models\Redirect model's capabilities, please read the comments from /config/redirects.php -> redirect_model
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see LICENSE for more information.
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.