Skip to content
Nested URLs redirect logic
Branch: master
Clone or download
zbiller Apply fixes from StyleCI (#4)
[ci skip] [skip ci]
Latest commit 66784ec Jul 14, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
config Apply fixes from StyleCI (#1) Jun 3, 2019
database/migrations added redirects migration Jun 2, 2019
src Apply fixes from StyleCI (#4) Jul 14, 2019
tests
.editorconfig added editorconfig file Jun 2, 2019
.gitattributes added gitattributes file Jun 2, 2019
.gitignore added gitignore file Jun 2, 2019
.scrutinizer.yml added scrutinizer configuration file Jun 2, 2019
.styleci.yml added style ci configuration file Jun 2, 2019
.travis.yml added travis ci configuration file Jun 2, 2019
CHANGELOG.md added changelog file Jun 2, 2019
CONTRIBUTING.md added contributing file Jun 2, 2019
LICENSE.md added license file Jun 2, 2019
README.md syntax fixed Jul 14, 2019
composer.json updated the package keywords Jun 2, 2019
phpunit.xml.dist added tests Jun 2, 2019

README.md

Nested redirects for Laravel

Build Status StyleCI Scrutinizer Code Quality

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 /original to /modified

    Accessing /original will redirect to /modified

  • You create another redirect from /modified to /modified-again

    Accessing /modified will redirect to /modified-again AND
    Accessoing /original will redirect to /modified-again

  • You create another redirect from /modified-again to /modified-yet-again

    Accessing /modified-again will redirect to /modified-yet-again AND
    Accessing /modified will redirect to /modified-yet-again AND
    Accessing /original will redirect to /modified-yet-again

  • You create another redirect from modified-yet-again to /original

    Accessing /modified-yet-again will redirect to /original AND
    Accessing /modified-again will redirect to /original AND
    Accessing /modified will redirect to /original

Installation

Install the package via Composer:

composer require neurony/laravel-redirects

Publish the config file with:

php artisan vendor:publish --provider="Neurony\Redirects\ServiceProvider" --tag="config"

Publish the migration file with:

php artisan vendor:publish --provider="Neurony\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 Neurony\Redirects\Middleware\RedirectRequests middleware.

Go to App\Http\Kernel and add the Neurony\Redirects\Middleware\RedirectRequests middleware in your $middlewareGroups groups of choice.

/**
 * The application's route middleware groups.
 *
 * @var array
 */
protected $middlewareGroups = [
    'web' => [
        ...
        \App\Http\Middleware\RedirectRequests::class,

Creating redirects

You should never use the Neurony\Redirects\Models\Redirect directly, as this is the default concrete implementation for the Neurony\Redirects\Contracts\RedirectModelContract.

Using the Neurony\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 Neurony\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 andrei.badea@neurony.ro 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.

You can’t perform that action at this time.