PHPackages                             law909/altorouter - 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. law909/altorouter

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

law909/altorouter
=================

A lightning fast router for PHP

1.0.7(3y ago)0270PHPPHP &gt;=7.0

Since May 10Pushed 3y ago1 watchersCompare

[ Source](https://github.com/law909/AltoRouter)[ Packagist](https://packagist.org/packages/law909/altorouter)[ Docs](https://github.com/niahoo/AltoRouter)[ RSS](/packages/law909-altorouter/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (9)Used By (0)

AltoRouter
==========

[](#altorouter)

AltoRouter is a small but powerful routing class for PHP 5.3+, heavily inspired by [klein.php](https://github.com/chriso/klein.php/).

- Dynamic routing with named parameters
- Reversed routing
- Flexible regular expression routing (inspired by [Sinatra](http://www.sinatrarb.com/))

Getting started
---------------

[](#getting-started)

1. PHP 5.3.x is required
2. Setup URL rewriting so that all requests are handled by **index.php**
3. Create an instance of AltoRouter, map your routes and match a request.
4. Have a look at the supplied example file for a better understanding on how to use AltoRouter(index.php).

Routing
-------

[](#routing)

```
$router = new AltoRouter();
$router->setBasePath('/AltoRouter');

// mapping routes
$router->map('GET|POST','/', 'home#index', 'home');
$router->map('GET','/users/', array('c' => 'UserController', 'a' => 'ListAction'));
$router->map('GET','/users/[i:id]', 'users#show', 'users_show');
$router->map('POST','/users/[i:id]/[delete|update:action]', 'usersController#doAction', 'users_do');

// reversed routing
$router->generate('users_show', array('id' => 5));
```

You can use the following limits on your named parameters. AltoRouter will create the correct regexes.

```
    *                    // Match all request URIs
    [i]                  // Match an integer
    [i:id]               // Match an integer as 'id'
    [a:action]           // Match alphanumeric characters as 'action'
    [h:key]              // Match hexadecimal characters as 'key'
    [:action]            // Match anything up to the next / or end of the URI as 'action'
    [create|edit:action] // Match either 'create' or 'edit' as 'action'
    [*]                  // Catch all (lazy, stops at the next trailing slash)
    [*:trailing]         // Catch all as 'trailing' (lazy)
    [**:trailing]        // Catch all (possessive - will match the rest of the URI)
    .[:format]?          // Match an optional parameter 'format' - a / or . before the block is also optional

Some more complicated examples

    /posts/[*:title][i:id]     // Matches "/posts/this-is-a-title-123"
    /output.[xml|json:format]? // Matches "/output", "output.xml", "output.json"
    /[:controller]?/[:action]? // Matches the typical /controller/action format
```

Additional info
---------------

[](#additional-info)

If you like AltoRouter, you might also like [PHP Router](//github.com/dannyvankooten/PHP-Router).

License
-------

[](#license)

(MIT License)

Copyright (c) 2012 Danny van Kooten

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 66.7% 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 ~504 days

Recently: every ~836 days

Total

8

Last Release

1268d ago

PHP version history (2 changes)1.0.0PHP &gt;=5.3.0

1.0.6PHP &gt;=7.0

### Community

Maintainers

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

---

Top Contributors

[![dannyvankooten](https://avatars.githubusercontent.com/u/885856?v=4)](https://github.com/dannyvankooten "dannyvankooten (8 commits)")[![law909](https://avatars.githubusercontent.com/u/380935?v=4)](https://github.com/law909 "law909 (3 commits)")[![koenpunt](https://avatars.githubusercontent.com/u/351038?v=4)](https://github.com/koenpunt "koenpunt (1 commits)")

---

Tags

routerroutinglightweight

### Embed Badge

![Health badge](/badges/law909-altorouter/health.svg)

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

###  Alternatives

[symfony/routing

Maps an HTTP request to a set of configuration variables

7.6k819.6M2.3k](/packages/symfony-routing)[nikic/fast-route

Fast request router for PHP

5.3k95.8M742](/packages/nikic-fast-route)[altorouter/altorouter

A lightning fast router for PHP

1.3k3.4M73](/packages/altorouter-altorouter)[aura/router

Powerful, flexible web routing for PSR-7 requests.

5001.5M69](/packages/aura-router)[aplus/routing

Aplus Framework Routing Library

2551.6M3](/packages/aplus-routing)[pmjones/auto-route

Automatically routes HTTP request to action classes.

19960.8k6](/packages/pmjones-auto-route)

PHPackages © 2026

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