Get support for middlewares/redirect

If you're new to LTH, please see our FAQ for more information on what it is we do.

Support Options

Unfortunately, there are currently no active helpers for this repository on the platform. Until they become available, we reccomend the following actions:

View Open Issues

Take a look to see if anyone else has experienced the same issue as you and if they managed to solve it.

Open an Issue

Make sure to read any relevant guidelines for opening issues on this repo before posting a new issue.

Sponsor directly

Check out the page and see if there are any options to sponsor this project or it's developers directly.

middlewares/redirect

middlewares/redirect

Latest Version on Packagist Software License Testing Total Downloads

Middleware to redirect old urls to new urls SEO friendly.

Requirements

Installation

This package is installable and autoloadable via Composer as middlewares/redirect.

composer require middlewares/redirect

Example

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

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 will be used to detect it automatically.

$responseFactory = new MyOwnResponseFactory();

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

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

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

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 for more information about recent changes and CONTRIBUTING for contributing details.

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

Our Mission

We want to make open source more sustainable. The entire platform was born from this and everything we do is in aid of this.

Interesting Articles

Thank you for checking out LiveTechHelper |
2025 © lth-dev incorporated

p-e622a1a2