PHPackages                             settermjd/regex-redirector - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. settermjd/regex-redirector

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

settermjd/regex-redirector
==========================

0.0.3(8y ago)010BSD-3-ClausePHPPHP ^5.6 || ^7.0

Since Jul 27Pushed 8y ago1 watchersCompare

[ Source](https://github.com/settermjd/regex-redirector)[ Packagist](https://packagist.org/packages/settermjd/regex-redirector)[ RSS](/packages/settermjd-regex-redirector/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (1)Versions (4)Used By (0)

Regex Redirector
================

[](#regex-redirector)

This is a simple package that simplifies the process of performing redirects by searching and replacing a pattern within the URL, if present. It's not meant to be, in any way, sophisticated.

Installing
----------

[](#installing)

To install the module, use Composer by running `composer require settermjd/regex-redirector`.

Getting Started
---------------

[](#getting-started)

The constructor takes two arguments:

1. An array. This is a simple key/value list of patterns to look for with patterns to replace
2. The currently requested URL.

The package provides two functions:

- `requiresRedirect()`: This tests if the requested URL requires a redirect
- `getRedirectUrl()`: Retrieves the URL that the current request should be redirected to

If you just want to test, use the first, if you want to redirect, use the second, which uses the first internally.

After initializing the object, pass the return value from `getRedirectUrl()` to PHP's [header](http://php.net/manual/de/function.header.php) function, as in the example below, and the request will be redirected.

```
