PHPackages                             serjoscha87/php-request-mapper - 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. serjoscha87/php-request-mapper

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

serjoscha87/php-request-mapper
==============================

auto router / mapper to do the heavy lifting for mapping requests to local fs files

3.0(1y ago)18[2 issues](https://github.com/serjoscha87/php-request-mapper/issues)MITPHPPHP &gt;=8.0

Since Mar 22Pushed 1y ago1 watchersCompare

[ Source](https://github.com/serjoscha87/php-request-mapper)[ Packagist](https://packagist.org/packages/serjoscha87/php-request-mapper)[ Docs](https://github.com/serjoscha87/php-request-mapper)[ RSS](/packages/serjoscha87-php-request-mapper/feed)WikiDiscussions master Synced today

READMEChangelog (4)DependenciesVersions (6)Used By (0)

*PHP request-mapper* / auto-router / request-to-file-resolver for *pretty URLs*
===============================================================================

[](#php-request-mapper--auto-router--request-to-file-resolver-for-pretty-urls)

[![Packagist](https://camo.githubusercontent.com/07489cac514a4ee31d647e12c5fa6335a3d8e055d0ce005da7d4e5b4b57942e4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7365726a6f7363686138372f7068702d726571756573742d6d61707065722e737667)](https://packagist.org/packages/serjoscha87/php-request-mapper)[![Total Downloads](https://camo.githubusercontent.com/0a8606311108736a71532141b9bbe610bb80dc6901a37470a33dff4b258433ae/68747470733a2f2f706f7365722e707567782e6f72672f7365726a6f7363686138372f7068702d726571756573742d6d61707065722f646f776e6c6f616473)](https://packagist.org/packages/serjoscha87/php-request-mapper)![php](https://camo.githubusercontent.com/fe030fb9faf59a6d34f16cd0c2a8e963c8579bb14f12378f8354db5cb90a8c12/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d352e782d7265642e737667)![php](https://camo.githubusercontent.com/a122196a9b430f7036f1c678826649b48e09dc67e345e78eaf0aa5db6d89ee43/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d372e782d7265642e737667)![php](https://camo.githubusercontent.com/c8563252142a1b6b18a7d6bcbbbb93f8d6d5c975876bb5b5a2d5fa176292d955/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e782d677265656e2e737667)

> DOC MOSTLY REMOVED (because it was written for an older approach) - I'M CURRENTLY REWORKING IT &lt;

Implementation examples / tests:
--------------------------------

[](#implementation-examples--tests)

Perhaps those examples render the complete README unnecessary.

Purpose
-------

[](#purpose)

Ever though that it can not be that hard to reflect pretty-url requets to files on your server's file-system? Well - trying it you will quickly face edge cases that will convince you of the opposite. This requets-mapper does the heavy lifting of reflecting pretty-url request to files on the local filesystem of the server while serving you a configurable abstraction layer. It can handle 404 requests out of the box so you do not have to concern about it.

The lib

- Basically renders the need of a php-router for manual route-bindings obsolete
- Can simply be dropped in any project to easily add pretty URLs that are automatically reflected to the filesystem

I primarily wrote this for using it within a framework for more or less static websites (not apps) I wrote some time ago. But perhaps this lib can be used beyond its actual purpose.

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

[](#installation)

`composer require serjoscha87/php-request-mapper`

### .htaccess

[](#htaccess)

**For Apache Webservers:**

*the all known 'wordpress' rewrite rule which rewrites all requests to things that do not physically exist to index.php:*

```
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
```

**Nginx rewrites requests to the index.php by default - no extra rules needed.**

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

[](#requirements)

- PHP8+ (because the lib makes use of named arguments and array unpacking)

Simple usage Example
--------------------

[](#simple-usage-example)

**filesystem:**

```
index.php
pages
- test.php
- home.php
- 404.php
- foobar (dir)
  - foobar.php
  - abc.php
  - detail.php

```

(of course the level of dir-nesting is not limited by the request-mapper)

### Examples for better understanding what the request mapper does for you

[](#examples-for-better-understanding-what-the-request-mapper-does-for-you)

considering the filesys structure given above (see "Simple usage Example"):

- Request to: `/test` -&gt; will deliver the content of `pages/test.php`
- Request to: `/quxx` -&gt; will deliver the content of `pages/404.php` (because there is no quxx.php in the pages dir)
- Request to: `/` -&gt; will deliver the content of `pages/home.php`
- Request to: `/home` -&gt; the requestmapper will tell you that a redirect to `/` is required (through `CurrentRequest::needsRedirect()` - you can use `CurrentRequest::getRedirectUri()` to get the redirect target)
- Request to: `/foobar/foobar` -&gt; the requestmapper will tell you that a redirect to `/foobar` is required (see above)
- Request to: `/foobar` -&gt; will deliver the content of `pages/foobar/foobar.php`
- Request to: `/foobar/detail/something` -&gt; will deliver the content of `pages/foobar/detail.php` and will pass everything after `/detail` to the php file
- Request to: `/foobar/abc` -&gt; like seen before ... nothing special. Will deliver the content `pages/foobar/abc.php`

misc
----

[](#misc)

This lib also works perfectly fine with great template engines / implementations like [BladeOne](https://github.com/serjoscha87/php-request-mapper)

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance12

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 79.2% 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 ~36 days

Total

4

Last Release

722d ago

Major Versions

0.5 → 1.02024-03-27

1.0 → 2.02024-05-02

2.0 → 3.02024-07-10

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4697715?v=4)[Serjoscha](/maintainers/serjoscha87)[@serjoscha87](https://github.com/serjoscha87)

---

Top Contributors

[![serjoscha87](https://avatars.githubusercontent.com/u/4697715?v=4)](https://github.com/serjoscha87 "serjoscha87 (19 commits)")[![bassauer-storms-media](https://avatars.githubusercontent.com/u/25793506?v=4)](https://github.com/bassauer-storms-media "bassauer-storms-media (5 commits)")

---

Tags

phpauto request mappingauto-routerauto request to file mapping

### Embed Badge

![Health badge](/badges/serjoscha87-php-request-mapper/health.svg)

```
[![Health](https://phpackages.com/badges/serjoscha87-php-request-mapper/health.svg)](https://phpackages.com/packages/serjoscha87-php-request-mapper)
```

###  Alternatives

[imanghafoori/laravel-anypass

A minimal yet powerful package to help you in development.

21623.4k](/packages/imanghafoori-laravel-anypass)

PHPackages © 2026

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