PHPackages                             truecastdesign/jsonredirects - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. truecastdesign/jsonredirects

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

truecastdesign/jsonredirects
============================

Json file based redirects with exact match and wildcard \* matching for changing higher up paths with sub categories so the sub categories get redirected as well.

v2.0.0(2y ago)0121[1 PRs](https://github.com/truecastdesign/jsonredirects/pulls)MITPHPPHP &gt;=5.5.0

Since Mar 29Pushed 2y ago1 watchersCompare

[ Source](https://github.com/truecastdesign/jsonredirects)[ Packagist](https://packagist.org/packages/truecastdesign/jsonredirects)[ RSS](/packages/truecastdesign-jsonredirects/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (1)DependenciesVersions (3)Used By (0)

jsonredirects
=============

[](#jsonredirects)

Json file based redirects with exact match and wildcard \* matching for changing higher up paths with sub categories so the sub categories get redirected as well.

Use
===

[](#use)

```
Truecast\Redirects::redirect(['request'=>$_SERVER['REQUEST_URI'], 'lookup'=>BP.'/redirects.json', 'type'=>'301']);
```

JSON File
=========

[](#json-file)

```
{
	"path1/path2/":"path3/",
	"path4/path5/*":"path4/path6/*",
	"path7/path9/*":"path7/path10/",
}
```

*First line:*Simple redirect. Key: request uri and value: redirected uri

*Second line:*Matches "path4/path5/path8/" redirects to "path4/path6/path8/" The path that matches the \* on the request is moved over to the end of the redirect uri in place of the \*

*Third line:*Matches "path7/path9/path8/" redirects to "path7/path10/" The path that matches the \* on the request is NOT moved over to the end of the redirect uri because there is no \* on the redirect

Editing JSON file with PHP
==========================

[](#editing-json-file-with-php)

Add redirect
------------

[](#add-redirect)

```
$Redirects = new App\Redirects(BP.'/config/redirects.json');
$Redirects->add($App->request->post->fromUrl, $App->request->post->toUrl);
```

Remove redirect
---------------

[](#remove-redirect)

```
$Redirects = new App\Redirects(BP.'/config/redirects.json');
$Redirects->remove($App->request->delete->fromUrl);
```

Get redirects list
------------------

[](#get-redirects-list)

```
$Redirects = new App\Redirects(BP.'/config/redirects.json');
$list = $Redirects->getRedirectsList();

// array ['from-url'=>'to-url', 'from-url'=>'to-url']
```

Clean URL
---------

[](#clean-url)

```
$Redirects = new App\Redirects(BP.'/config/redirects.json');
$cleanedURL = $Redirects->cleanUrl($url);
```

Notes
=====

[](#notes)

This code works well in a routes script at the top before other custom routes are checked.

It is only designed to match the end of the url and not a middle part like path/\*/path If that would be helpful, let me know and I will see what I can do.

Thanks!

I hope this is helpful.

###  Health Score

25

—

LowBetter than 36% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~1578 days

Total

2

Last Release

1063d ago

Major Versions

v1.0.0 → v2.0.02023-07-25

### Community

Maintainers

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

---

Top Contributors

[![truecastdesign](https://avatars.githubusercontent.com/u/18723650?v=4)](https://github.com/truecastdesign "truecastdesign (3 commits)")

---

Tags

phpjsonredirect301

### Embed Badge

![Health badge](/badges/truecastdesign-jsonredirects/health.svg)

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

###  Alternatives

[adhocore/json-fixer

Fix/repair truncated JSON data

51569.3k2](/packages/adhocore-json-fixer)[m1/vars

Vars is a simple to use and easily extendable configuration loader with in built loaders for ini, json, PHP, toml, XML and yaml/yml file types. It also comes with in built support for Silex and more frameworks to come soon.

64124.3k1](/packages/m1-vars)[blancks/fast-jsonpatch-php

Class designed to efficiently handle JSON Patch operations in accordance with the RFC 6902 specification

397.9k](/packages/blancks-fast-jsonpatch-php)[josantonius/json

PHP simple library for managing Json files.

1722.4k10](/packages/josantonius-json)

PHPackages © 2026

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