PHPackages                             middlewares/base-path - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. middlewares/base-path

ActiveLibrary[HTTP &amp; Networking](/categories/http)

middlewares/base-path
=====================

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

v2.2.0(1y ago)31.4M↓20.6%7MITPHPPHP ^7.2 || ^8.0CI passing

Since Oct 1Pushed 1y ago1 watchersCompare

[ Source](https://github.com/middlewares/base-path)[ Packagist](https://packagist.org/packages/middlewares/base-path)[ Docs](https://github.com/middlewares/base-path)[ RSS](/packages/middlewares-base-path/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (13)Used By (7)

middlewares/base-path
=====================

[](#middlewaresbase-path)

[![Latest Version on Packagist](https://camo.githubusercontent.com/5de215d43f78bb1998fbafdf130e0cb06d98bfc98359efd539b30dde331e96b4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6964646c6577617265732f626173652d706174682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/middlewares/base-path)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Testing](https://github.com/middlewares/base-path/workflows/testing/badge.svg)](https://github.com/middlewares/base-path/workflows/testing/badge.svg)[![Total Downloads](https://camo.githubusercontent.com/8c965ddd464824ecb12205852c19c2baccccee1ef44827bfe99511e432d53bbe/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6964646c6577617265732f626173652d706174682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/middlewares/base-path)

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
------------

[](#requirements)

- PHP &gt;= 7.2
- A [PSR-7](https://packagist.org/providers/psr/http-message-implementation) http message implementation ([Diactoros](https://github.com/zendframework/zend-diactoros), [Guzzle](https://github.com/guzzle/psr7), [Slim](https://github.com/slimphp/Slim), etc...)
- A [PSR-15 middleware dispatcher](https://github.com/middlewares/awesome-psr15-middlewares#dispatcher)

Installation
------------

[](#installation)

This package is installable and autoloadable via Composer as [middlewares/base-path](https://packagist.org/packages/middlewares/base-path).

```
composer require middlewares/base-path
```

Usage
-----

[](#usage)

Set the prefix to remove:

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

### fixLocation

[](#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
```

### attribute

[](#attribute)

This method will store the original path in an attribute.

```
// Save the original uri with basepath in the custom attribute "before-basepath-uri"
$basepath = (new Middlewares\BasePath())->attribute('pre-basepath-path');
```

---

Please see [CHANGELOG](CHANGELOG.md) for more information about recent changes and [CONTRIBUTING](CONTRIBUTING.md) for contributing details.

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

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance46

Moderate activity, may be stable

Popularity43

Moderate usage in the ecosystem

Community18

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 93.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~281 days

Recently: every ~605 days

Total

12

Last Release

421d ago

Major Versions

v0.5.0 → v1.0.02018-01-24

v1.1.0 → v2.0.02019-11-30

PHP version history (4 changes)v0.1.0PHP ^5.6 || ^7.0

v0.5.0PHP ^7.0

v2.0.0PHP ^7.2

v2.0.1PHP ^7.2 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/e99df56b617f4af8cf0556a51a0ca20c7420104920c57d7e9eab093f92bb744f?d=identicon)[oscarotero](/maintainers/oscarotero)

![](https://www.gravatar.com/avatar/42e0d72f42eb7d84f67e20d28606da42e5a3248ca908b1eadb4366aafeae2561?d=identicon)[filisko](/maintainers/filisko)

---

Top Contributors

[![oscarotero](https://avatars.githubusercontent.com/u/377873?v=4)](https://github.com/oscarotero "oscarotero (46 commits)")[![filisko](https://avatars.githubusercontent.com/u/8798694?v=4)](https://github.com/filisko "filisko (3 commits)")

---

Tags

base-pathhttpmiddlewarepsr-15httppsr-7middlewareserverpsr-15

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/middlewares-base-path/health.svg)

```
[![Health](https://phpackages.com/badges/middlewares-base-path/health.svg)](https://phpackages.com/packages/middlewares-base-path)
```

###  Alternatives

[middlewares/request-handler

Middleware to execute request handlers

451.6M26](/packages/middlewares-request-handler)[middlewares/fast-route

Middleware to use FastRoute

96191.1k15](/packages/middlewares-fast-route)[middlewares/negotiation

Middleware to implement content negotiation

47442.1k11](/packages/middlewares-negotiation)[middlewares/payload

Middleware to parse the body of the request with support for json, csv and url-encode

32466.8k17](/packages/middlewares-payload)[middlewares/http-authentication

Middleware to implement Basic and Digest Http authentication

35302.0k2](/packages/middlewares-http-authentication)[middlewares/client-ip

Middleware to detect the client ip and save it as a request attribute

16629.7k9](/packages/middlewares-client-ip)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
