All Projects → spatie → Laravel Missing Page Redirector

spatie / Laravel Missing Page Redirector

Licence: mit
Redirect missing pages in your Laravel application

Projects that are alternatives of or similar to Laravel Missing Page Redirector

Laravel Seo Tools
Laravel Seo package for Content writer/admin/web master who do not know programming but want to edit/update SEO tags from dashboard
Stars: ✭ 99 (-73.81%)
Mutual labels:  laravel, seo
Seotools
SEO Tools for Laravel
Stars: ✭ 2,406 (+536.51%)
Mutual labels:  laravel, seo
Open Graph
Library that assists in building Open Graph meta tags
Stars: ✭ 112 (-70.37%)
Mutual labels:  laravel, seo
Laravel Seo
SEO package made for maximum customization and flexibility
Stars: ✭ 130 (-65.61%)
Mutual labels:  laravel, seo
Laravel Robots Middleware
Enable or disable the indexing of your app
Stars: ✭ 259 (-31.48%)
Mutual labels:  laravel, seo
Laravel Sitemap
Create and generate sitemaps with ease
Stars: ✭ 1,325 (+250.53%)
Mutual labels:  laravel, seo
Lara Head
Easily setup SEO in your laravel project with lara-head ❤️ @code4mk
Stars: ✭ 169 (-55.29%)
Mutual labels:  laravel, seo
Lashop
Simple shop based on Laravel 7.3
Stars: ✭ 60 (-84.13%)
Mutual labels:  laravel, seo
Laravel Link Checker
Check all links in a Laravel application
Stars: ✭ 253 (-33.07%)
Mutual labels:  laravel, seo
Laravelmetatags
The most powerful and extendable tools for managing SEO Meta Tags in your Laravel project
Stars: ✭ 226 (-40.21%)
Mutual labels:  laravel, seo
Seo Manager
Seo Manager Package for Laravel ( with Localization )
Stars: ✭ 192 (-49.21%)
Mutual labels:  laravel, seo
Laravel Paginateroute
Laravel router extension to easily use Laravel's paginator without the query string
Stars: ✭ 306 (-19.05%)
Mutual labels:  laravel, seo
Seo Helper
🔍 SEO Helper is a package that provides tools and helpers for SEO (Search Engine Optimization).
Stars: ✭ 262 (-30.69%)
Mutual labels:  laravel, seo
Laravel Referer
Remember a visitor's original referer
Stars: ✭ 339 (-10.32%)
Mutual labels:  laravel, seo
Ulearn
ULEARN - Open Source(FREE) LMS script in Laravel 5.8 and ReactJS 16.9
Stars: ✭ 368 (-2.65%)
Mutual labels:  laravel
Starter Laravel Angular
Laravel and AngularJS Starter Application Boilerplate featuring Laravel 5.3 and AngularJS 1.5.8
Stars: ✭ 373 (-1.32%)
Mutual labels:  laravel
Laravel Shopping Cart
🛒 Shopping cart for Laravel Application.
Stars: ✭ 369 (-2.38%)
Mutual labels:  laravel
Laravel Onesignal
OneSignal Push Notifications for Laravel
Stars: ✭ 369 (-2.38%)
Mutual labels:  laravel
Elasticsearch
The missing elasticsearch ORM for Laravel, Lumen and Native php applications
Stars: ✭ 375 (-0.79%)
Mutual labels:  laravel
Laravel
[DEPRECATED] See https://github.com/lucidarch/lucid
Stars: ✭ 373 (-1.32%)
Mutual labels:  laravel

Redirect missing pages in your Laravel application

Latest Version on Packagist Software License Test Status Code Style Status Total Downloads

When transitioning from a old site to a new one your URLs may change. If your old site was popular you probably want to retain your SEO worth. One way of doing this is by providing permanent redirects from your old URLs to your new URLs. This package makes that process very easy.

When installed you only need to add your redirects to the config file. Want to use the database as your source of redirects? No problem!

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package via composer:

composer require spatie/laravel-missing-page-redirector

The package will automatically register itself.

Next you must register the Spatie\MissingPageRedirector\RedirectsMissingPages-middleware:

//app/Http/Kernel.php

protected $middleware = [
       ...
       \Spatie\MissingPageRedirector\RedirectsMissingPages::class,
    ],

Finally you must publish the config file:

php artisan vendor:publish --provider="Spatie\MissingPageRedirector\MissingPageRedirectorServiceProvider"

This is the contents of the published config file:

return [
    /*
     * This is the class responsible for providing the URLs which must be redirected.
     * The only requirement for the redirector is that it needs to implement the
     * `Spatie\MissingPageRedirector\Redirector\Redirector`-interface
     */
    'redirector' => \Spatie\MissingPageRedirector\Redirector\ConfigurationRedirector::class,
    
    /*
     * By default the package will only redirect 404s. If you want to redirect on other
     * response codes, just add them to the array. Leave the array empty to redirect
     * always no matter what the response code.
     */
    'redirect_status_codes' => [
        \Symfony\Component\HttpFoundation\Response::HTTP_NOT_FOUND
    ],
    
    /*
     * When using the `ConfigurationRedirector` you can specify the redirects in this array.
     * You can use Laravel's route parameters here.
     */
    'redirects' => [
//        '/non-existing-page' => '/existing-page',
//        '/old-blog/{url}' => '/new-blog/{url}',
    ],

];

Usage

Creating a redirect is easy. You just have to add an entry to the redirects key in the config file.

'redirects' => [
   '/non-existing-page' => '/existing-page',
],

You may use route parameters like you're used to when using Laravel's routes:

    'redirects' => [
       '/old-blog/{url}' => '/new-blog/{url}',
    ],

Optional parameters are also... an option:

    'redirects' => [
       '/old-blog/{url?}' => '/new-blog/{url}',
    ],

By default it only redirects if the request has a 404 response code but it's possible to be redirected on any response code. To achieve this you may change the redirect_status_codes option to an array of response codes or leave it empty if you wish to be redirected no matter what the response code was sent to the URL. You may override this using the following syntax to achieve this:

    'redirect_status_codes' => [\Symfony\Component\HttpFoundation\Response::HTTP_NOT_FOUND],

It is also possible to optionally specify which http response code is used when performing the redirect. By default the 301 Moved Permanently response code is set. You may override this using the following syntax:

    'redirects' => [
       'old-page' => ['/new-page', 302],
    ],

Events

The package will fire a RouteWasHit event when it found a redirect for the route. A RedirectNotFound is fired when no redirect was found.

Creating your own redirector

By default this package will use the Spatie\MissingPageRedirector\Redirector\ConfigurationRedirector which will get its redirects from the config file. If you want to use another source for your redirects (for example a database) you can create your own redirector.

A valid redirector is any class that implements the Spatie\MissingPageRedirector\Redirector\Redirector-interface. That interface looks like this:

namespace Spatie\MissingPageRedirector\Redirector;

use Symfony\Component\HttpFoundation\Request;

interface Redirector
{
    public function getRedirectsFor(Request $request): array;
}

The getRedirectsFor method should return an array in which the keys are the old URLs and the values the new URLs.

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].