PHPackages                             middlewares/redirect - 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/redirect

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

middlewares/redirect
====================

A redirect repository for PSR-15 middleware packages

v2.1.0(1y ago)520.1k—0%31MITPHPPHP ^7.2 || ^8.0CI passing

Since Sep 19Pushed 1y ago2 watchersCompare

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

READMEChangelog (10)Dependencies (8)Versions (11)Used By (1)

middlewares/redirect
====================

[](#middlewaresredirect)

[![Latest Version on Packagist](https://camo.githubusercontent.com/724777ad37a8f786217a229235a83fc7e15e8b7f94f387dea497b4a4c9c4e695/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6964646c6577617265732f72656469726563742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/middlewares/redirect)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Testing](https://github.com/middlewares/redirect/workflows/testing/badge.svg)](https://github.com/middlewares/redirect/workflows/testing/badge.svg)[![Total Downloads](https://camo.githubusercontent.com/ba5abf0dd11a358b5375f19a7a0a314bf52053fbe14bf595c5b9ff3fdfe44dac/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6964646c6577617265732f72656469726563742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/middlewares/redirect)

Middleware to redirect old urls to new urls SEO friendly.

Requirements
------------

[](#requirements)

- PHP &gt;= 7.2
- A [PSR-7 http library](https://github.com/middlewares/awesome-psr15-middlewares#psr-7-implementations)
- 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/redirect](https://packagist.org/packages/middlewares/redirect).

```
composer require middlewares/redirect
```

Example
-------

[](#example)

```
Dispatcher::run([
	new Middlewares\Redirect(['/old-url' => '/new-url'])
]);
```

Usage
-----

[](#usage)

You can use an array or an object extending `ArrayAccess` interface with the urls to redirect, the key is the old url and the value the new.

```
$redirections = [
	'/corporative-info' => '/about-us',
	'/post/2390' => '/post/new-psr15-middlewares',
];

$redirect = new Middlewares\Redirect($redirections);
```

Optionally, you can provide a `Psr\Http\Message\ResponseFactoryInterface` as the second argument to create the redirect responses. If it's not defined, [Middleware\\Utils\\Factory](https://github.com/middlewares/utils#factory) will be used to detect it automatically.

```
$responseFactory = new MyOwnResponseFactory();

$redirect = new Middlewares\Redirect($redirections, $responseFactory);
```

### permanent

[](#permanent)

Use temporary or permanent redirection HTTP status code for the response. Enabled by default.

```
//Temporary redirections (302)
$redirect = (new Middlewares\Redirect($redirections))->permanent(false);
```

### query

[](#query)

Take the query part of the URI into account when matching redirects. Enabled by default.

```
//Ignore url query
$redirect = (new Middlewares\Redirect($redirections))->query(false);
```

### method

[](#method)

This option accepts an array with the allowed HTTP request methods. (By default is: `['GET']`.)

```
//Redirects GET and HEAD requests
$redirect = (new Middlewares\Redirect($redirections))->method(['GET', 'HEAD']);
```

---

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

47

—

FairBetter than 94% of packages

Maintenance46

Moderate activity, may be stable

Popularity34

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 81.3% 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 ~304 days

Recently: every ~605 days

Total

10

Last Release

413d ago

Major Versions

v0.3.1 → v1.0.02018-01-27

v1.1.0 → v2.0.02019-12-06

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

v0.3.0PHP ^7.0

v2.0.0PHP ^7.2

v2.0.1PHP ^7.2 || ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/147145?v=4)[Cees-Jan Kiewiet](/maintainers/WyriHaximus)[@WyriHaximus](https://github.com/WyriHaximus)

![](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 (39 commits)")[![WyriHaximus](https://avatars.githubusercontent.com/u/147145?v=4)](https://github.com/WyriHaximus "WyriHaximus (5 commits)")[![ajgarlag](https://avatars.githubusercontent.com/u/388184?v=4)](https://github.com/ajgarlag "ajgarlag (2 commits)")[![filisko](https://avatars.githubusercontent.com/u/8798694?v=4)](https://github.com/filisko "filisko (2 commits)")

---

Tags

httpmiddlewarepsr-15redirectsseohttppsr-7middlewareserverpsr-15redirect

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[middlewares/request-handler

Middleware to execute request handlers

451.6M25](/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.1k10](/packages/middlewares-negotiation)[middlewares/payload

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

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

Middleware to implement Basic and Digest Http authentication

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

Middleware to use Whoops as error handler

33205.4k24](/packages/middlewares-whoops)

PHPackages © 2026

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