Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sirodiaz/laravel-redirection
Laravel 8, 9 and 10 package to manage URL redirections inside your Laravel application using different data sources. It allows a better SEO support for your Laravel site.
https://github.com/sirodiaz/laravel-redirection
database laravel laravel-10 laravel-10-package laravel-8 laravel-8-package laravel-9 laravel-9-package laravel-framework laravel-package laravel-redirect php seo seo-optimization url url-redirect url-redirection url-redirections
Last synced: 28 days ago
JSON representation
Laravel 8, 9 and 10 package to manage URL redirections inside your Laravel application using different data sources. It allows a better SEO support for your Laravel site.
- Host: GitHub
- URL: https://github.com/sirodiaz/laravel-redirection
- Owner: SiroDiaz
- License: mit
- Created: 2021-10-06T08:14:10.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-02-10T13:06:57.000Z (9 months ago)
- Last Synced: 2024-10-11T11:42:12.236Z (28 days ago)
- Topics: database, laravel, laravel-10, laravel-10-package, laravel-8, laravel-8-package, laravel-9, laravel-9-package, laravel-framework, laravel-package, laravel-redirect, php, seo, seo-optimization, url, url-redirect, url-redirection, url-redirections
- Language: PHP
- Homepage:
- Size: 56.6 KB
- Stars: 61
- Watchers: 2
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
# Laravel package for manage your URL redirects in database or other sources to get better SEO results
[![Latest Version on Packagist](https://img.shields.io/packagist/v/sirodiaz/laravel-redirection.svg?style=flat-square)](https://packagist.org/packages/SiroDiaz/laravel-redirection)
[![run-tests](https://github.com/SiroDiaz/laravel-redirection/actions/workflows/run-tests.yml/badge.svg)](https://github.com/SiroDiaz/laravel-redirection/actions/workflows/run-tests.yml)
[![Check & fix styling](https://github.com/SiroDiaz/laravel-redirection/actions/workflows/php-cs-fixer.yml/badge.svg?branch=main)](https://github.com/SiroDiaz/laravel-redirection/actions/workflows/php-cs-fixer.yml)
[![Total Downloads](https://img.shields.io/packagist/dt/SiroDiaz/laravel-redirection.svg?style=flat-square)](https://packagist.org/packages/SiroDiaz/laravel-redirection)## Requirements
You need PHP 8.0 or higher. It is tested and designed for Laravel 9 and 10.
This package will receive updates for future Laravel versions. Previous Laravel versions
are not contemplated so use [Neurony/laravel-redirects](https://github.com/Neurony/laravel-redirects) package for
older Laravel versions.## Installation
You can install the package via composer:
```bash
composer require SiroDiaz/laravel-redirection
```You can publish and run the migrations with:
```bash
php artisan vendor:publish --provider="SiroDiaz\Redirection\RedirectionServiceProvider" --tag="redirection-migrations"
php artisan migrate
```You can publish the config file with:
```bash
php artisan vendor:publish --provider="SiroDiaz\Redirection\RedirectionServiceProvider" --tag="redirection-config"
```This is the contents of the published config file:
```php
[
301 => 'Permanent (301)',
302 => 'Normal (302)',
307 => 'Temporary (307)',
],/*
|--------------------------------------------------------------------------
| Default Redirect status code (in case of not defined)
|--------------------------------------------------------------------------
|
| Status code used by default to redirect from an old URL to a new mapped
| URL.
|
*/
'default_status_code' => (int)env('REDIRECT_DEFAULT_STATUS', 301),/*
|--------------------------------------------------------------------------
| Case sensitivity
|--------------------------------------------------------------------------
|
| Whether to match URLs case sensitively or not.
| Default to false because most URLs are not case sensitive.
|
*/
'case-sensitive' => (bool) env('REDIRECT_CASE_SENSITIVE', false),/*
|--------------------------------------------------------------------------
| Redirect Driver
|--------------------------------------------------------------------------
|
| Here you may specify the default redirect driver that you want to use.
| The "config" driver is used by default when you want to code faster.
| Consider database driver better for admin panel configuration backed by
| a relational DB.
|
*/
'driver' => env('REDIRECT_DRIVER', 'config'),/*
|--------------------------------------------------------------------------
| Array containing all available drivers and its implementations and source
|--------------------------------------------------------------------------
|
| Concrete implementation for the "redirection model".
| To extend or replace this functionality, change the value below with
| your full "redirection model" FQN.
|
| Your class will have to (first option is recommended):
| - extend the "SiroDiaz\Redirection\Models\Redirection" class
| - or at least implement the "SiroDiaz\Redirection\Contracts\RedirectionModelContract" interface.
|
| Regardless of the concrete implementation below, you can still use it like:
| - app('redirection.') OR app('\SiroDiaz\Redirection\Contracts\RedirectionModelContract')
| - or you could even use your own class as a direct implementation. For this
| case you must extend from "SiroDiaz\Redirection\Models\Redirection" model class and
| replace in the published config file 'drivers.database.source'.
|
|
*/
'drivers' => [
'config' => [
'driver' => SiroDiaz\Redirection\Drivers\FileRedirector::class,
'source' => 'redirection.urls',
],
'database' => [
'driver' => SiroDiaz\Redirection\Drivers\DatabaseRedirector::class,
'source' => SiroDiaz\Redirection\Models\Redirection::class,
],
],/*
|--------------------------------------------------------------------------
| Url list with redirections used for config driver
|--------------------------------------------------------------------------
|
| You can use urls array of two different ways. The simple one uses the
| default redirect status code ('redirection.default_status_code').
| Example:
| 'urls' => [
| '/old/url' => '/new/url',
| '/another/old/url' => '/another/new/url',
| '/url/with?id=123' => '/url/with/123',
| ],
|
| The second way to write redirect urls in your config/redirection.php
| is using associative arrays. You can combine this method with the previous one.
| Look at this example:
| 'urls' => [
| '/old/url' => ['new_url' => '/new/url', 'status_code' => 302],
| '/another/old/url' => '/another/new/url',
| '/url/with?id=123' => ['new_url' => '/url/with/123'],
| ],
|
*/
'urls' => [],];
```
You can change and extend the default `SiroDiaz\Redirection\Models\Redirection` model class.
Image that you want to add some methods or fields. You would need to create a new model class, for example `App\Models\Redirect`.Here is a basic example of how to extend the functionality of the default Redirection model.
We want to include support for Laravel BackPack admin panel would be:
```php