laravel-robots-middleware

Enable or disable the indexing of your app

Github stars Tracking Chart

Enable or disable the indexing of your app

Latest Version on Packagist
Software License
Build Status
SensioLabsInsight
Quality Score
StyleCI
Total Downloads

A tiny, opinionated package to enable or disable indexing your site via a middleware in Laravel.

More on the Robots meta tag: https://developers.google.com/webmasters/control-crawl-index/docs/robots_meta_tag

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.

Installation

You can install the package via composer:

$ composer require spatie/laravel-robots-middleware

Usage

By default, the middleware enables indexing on all pages. You'll probably want to inherit your own class containing you application's indexing rule handler.

// app/Http/Middleware/MyRobotsMiddleware.php

use Illuminate\Http\Request;
use Spatie\RobotsMiddleware\RobotsMiddleware;

class MyRobotsMiddleware extends RobotsMiddleware
{
    /**
     * @return string, bool
     */
    protected function shouldIndex(Request $request)
    {
        return $request->segment(1) !== 'admin';
    }
}

Next, simply register the newly created class in your middleware stack.

// app/Http/Kernel.php

class Kernel extends HttpKernel
{
    protected $middleware = [
        // ...
        \App\Http\Middleware\MyRobotsMiddleware::class,
    ];
    
    // ...
}

That's it! Responses will now always have an x-robots-tag in their headers, containing an all or none value.

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING for details. Due to nature of this package, there's a fair chance features won't be accepted to keep it light and opinionated.

Security

If you discover any security related issues, please email freek@spatie.be instead of using the issue tracker.

Postcardware

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.

We publish all received postcards on our company website.

Credits

Support us

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.

Does your business depend on our contributions? Reach out and support us on Patreon.
All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.

License

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

Overview

Name With Ownerspatie/laravel-robots-middleware
Primary LanguagePHP
Program languagePHP (Language Count: 1)
Platform
License:MIT License
Release Count11
Last Release Name1.4.0 (Posted on )
First Release Name1.0.0 (Posted on )
Created At2016-01-04 19:24:34
Pushed At2024-03-11 16:05:48
Last Commit At
Stargazers Count317
Watchers Count6
Fork Count33
Commits Count76
Has Issues Enabled
Issues Count5
Issue Open Count0
Pull Requests Count9
Pull Requests Open Count0
Pull Requests Close Count11
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private
To the top