Skip to content

A PSR-15 middleware to remove trailing slash in URI

License

Notifications You must be signed in to change notification settings

t0mmy742/trailing-slash-middleware

Repository files navigation

Trailing Slash Middleware (PSR-15)

Tests Coverage Status

This middleware remove trailing slash from URI. It implements PSR-15 MiddlewareInterface and need a PSR-17 ResponseFactory to work.

Installation

$ composer require t0mmy742/trailing-slash-middleware

Usage

<?php

use t0mmy742\Middleware\TrailingSlashMiddleware;

$responseFactory = new \Your\PSR17\ResponseFactory();
$middleware = new TrailingSlashMiddleware($responseFactory);

If path does not contain trailing slash, or if it is home ('/'), it does nothing. Otherwise, if it is a GET request, it creates a new Response with a 301 Permanent Redirect to the new URI (if is is not a GET request, it just handles request with new URI).

About

A PSR-15 middleware to remove trailing slash in URI

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages