middlewares/base-path

Middleware to remove the prefix from the uri path of the request.

v2.0.0 2019-11-30 01:50 UTC

This package is auto-updated.

Last update: 2020-05-30 00:58:56 UTC


README

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

Middleware to remove the prefix from the uri path of the request. This is useful to combine with routers if the root of the website is in a subdirectory. For example, if the root of your website is /web/public, a request with the uri /web/public/post/34 will be converted to /post/34.

Requirements

Installation

This package is installable and autoloadable via Composer as middlewares/base-path.

composer require middlewares/base-path

Usage

Set the prefix to remove:

Dispatcher::run([
	new Middlewares\BasePath('/base/path')
]);

fixLocation

Used to add the prefix to the Location header (for redirects). For example:

$response = Dispatcher::run([
    (new Middlewares\BasePath('/base/path'))->fixLocation(),

    function () {
        return Factory::createResponse(301)->withHeader('Location', '/post/1');
    }
]);

echo $response->getHeader('Location'); // Returns /base/path/post/1

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

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