Middleware to normalize the trailing slash of the uri path

v1.1.0 2018-08-04 10:41 UTC


Latest Version on Packagist Software License Build Status Quality Score Total Downloads SensioLabs Insight

Middleware to normalize the trailing slash of the uri path. By default removes the slash so, for example, /post/23/ is converted to /post/23. Useful if you have problems with the router.



This package is installable and autoloadable via Composer as middlewares/trailing-slash.

composer require middlewares/trailing-slash


$dispatcher = new Dispatcher([
	(new Middlewares\TrailingSlash(true))

$response = $dispatcher->dispatch(new ServerRequest());


__construct(booll $trailingSlash = false)

Set true to add the slash instead remove so, for example, post/23 is converted to /post/23/. Note that if the path contains an extension, the slash is NOT added. For example, images/image.png remains the same, instead be converted to images/image.png/.


Set this option to return a 301 response redirecting to the new path

responseFactory(Psr\Http\Message\ResponseFactoryInterface $responseFactory)

A PSR-17 factory to create 301 responses.

Please see CHANGELOG for more information about recent changes and CONTRIBUTING for contributing details.

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