aurawindsurfing/slashremovemiddleware

This package adds 301 redirect to all routes with trailing slashes.

v1.0.4 2022-11-28 13:27 UTC

This package is auto-updated.

Last update: 2024-04-28 16:50:21 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

It is important to remove trailing slashed from applications made with laravel and it is bad for SEO as Google will index your page twice, once with slash and once without it. The correct behaviour is to create 301 for ever page with trailing slash to avoid content duplication in search results.

Here is the source: https://developers.google.com/search/blog/2010/04/to-slash-or-not-to-slash

Before you start

An easy way to check if your app is behaving properly is to create a test route in routes/web.php like this:

Route::get('/foobar', function () {
    return 'simple test';
});

Then visit this endpoint with trailing slash yourapp.test/foobar/

If "simple test" was displayed and trailing slash did not dissapear from your url in the browser window then Google will not be happy about it and you need to fix it.

Installation

Via Composer

composer require aurawindsurfing/slashremovemiddleware

Usage

This package will auto register itself in Laravel 6 and higher.

Now repeat the same test.

You should be redirected to the same url but without trailing slash yourapp.test/foobar and see the same text.

Now Google will only index every page once.

Change log

Please see the changelog for more information on what has changed recently.

Testing

composer test

Contributing

Please see contributing.md for details and a todolist.

Security

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

Credits

License

license. Please see the license file for more information.