PHPackages                             leeoniya/route66 - 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. [Framework](/categories/framework)
4. /
5. leeoniya/route66

ActiveLibrary[Framework](/categories/framework)

leeoniya/route66
================

PHP micro-router

158713[3 issues](https://github.com/leeoniya/Route66.php/issues)PHP

Since Jan 27Pushed 4y ago5 watchersCompare

[ Source](https://github.com/leeoniya/Route66.php)[ Packagist](https://packagist.org/packages/leeoniya/route66)[ RSS](/packages/leeoniya-route66/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Route66.php
-----------

[](#route66php)

PHP micro-router *(MIT Licensed)*

- Concise, simple syntax wrapping a full feature set
- Easy install; Composer or single file include (~200 SLOC)
- Low routing overhead (&lt; 1ms)\*

Route66 was written to add [some features](#added-feats) to the minimalist [Macaw](https://github.com/NoahBuscher/Macaw) router without bloating it.

#### Nginx config example

[](#nginx-config-example)

```
server {
	index index.html index.htm index.php;

	location / {
		try_files $uri $uri/ /index.php?/$uri;
	}

	location ~ \.php$ {
		fastcgi_pass 127.0.0.1:9000;
		fastcgi_index index.php;
		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
		include fastcgi_params;
	}
}

```

#### Install (require or Composer)

[](#install-require-or-composer)

```
require 'Route66.php';

```

```
{
	"require": {
		"leeoniya/route66": "dev-master"
	}
}

```

#### Basic example

[](#basic-example)

```
// front controller (index.php)
require 'Route66.php';

use Route66 as R;

R::get('/', function() {
	echo 'Hello world!';
});

R::dispatch();

```

#### HTTP methods

[](#http-methods)

```
// any HTTP method can be bound via static invocation using its name
R::post('/topics', function() {});

// multiple methods
R::match('post|put', '/comment', function() {});

// equivalent to R::match('get|post|put|patch|delete|head|options',..)
R::any('/', function() {};)

```

#### Named params &amp; validation

[](#named-params--validation)

```
// basic param (all characters except '/')
R::get('/posts/@id',       function($id) {});

// param validated by regex alias
R::get('/posts/@id:alpha', function($id) {});

// aliases and regexs can be broken out for readability
R::get('/posts/@id',       function($id) {}, ['id' => ':alpha']);
R::get('/posts/@id',       function($id) {}, ['id' => '\w{12}']);

// define a custom alias
R::alias(':date', '[0-9]{4}-[0-9]{2}-[0-9]{2}');

```

#### Optional segments &amp; params

[](#optional-segments--params)

```
// optional params with defaults (set in handler)
R::get('/posts(/@year(/@month(/@day)))', function($year = 2015, $month = 6, $day = 15) {});

// regex alias without a param (non-capturing)
R::get('/posts(/:slug)', function() {});

// optional trailing slash (though rtrim-ing it from REQUEST_URI before dispatch is faster)
R::get('/blog/?', function() {});

```

#### Un-named params

[](#un-named-params)

```
// un-named params via regex capture groups
R::get('/posts/(\w{12})', function($id) {});

```

#### Route prefixing (base path)

[](#route-prefixing-base-path)

```
R::base('/blog');
R::get('/posts', function() {});	// maps to /blog/posts

R::base('/admin');
R::get('/login', function() {});	// maps to /admin/login

```

#### Before pre-filter (fall-through)

[](#before-pre-filter-fall-through)

```
// before all /admin* routes
R::get('/admin(/:all)', function() {
	// verify valid session, etc...
	return R::NOHALT;		// fall through to additional routes
});

R::get('/admin/dashboard', function() {
	// show dashboard...
});

```

#### Custom catch-all (no route found)

[](#custom-catch-all-no-route-found)

```
R::nomatch(function($meth, $uri) {
	header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found");
	exit('404 Not Found.');
});

```

#### Custom dispatch (e.g. internal redirects)

[](#custom-dispatch-eg-internal-redirects)

```
R::dispatch('get', '/blog');

```

#### Route caching

[](#route-caching)

```
// example of storing compiled routes in session
session_start();

if ($routes = @$_SESSION['routes'])
	R::import($routes);

// define all routes here

R::dispatch();

if (!isset($_SESSION['routes']))
	$_SESSION['routes'] = R::export();

```

#### Named routes &amp; reverse routing

[](#named-routes--reverse-routing)

```
// un-named
R::get('/users/@id', function($id) {}, ['id'=>':alpha']);

// named (the trailing 2 args can be passed in any order. all below are equivalent.)
R::get('/users/@id', function($id) {}, 'named1');
R::get('/users/@id', function($id) {}, ['id'=>':alpha'], 'named1');
R::get('/users/@id', function($id) {}, 'named1', ['id'=>':alpha']);

// dispatch a named route
R::dispatch('get', 'named1', ['id' => 'abc123']);

```

#### Util methods

[](#util-methods)

```
R::is_ajax();
R::is_https();
R::redirect($location, $code = 301);

```

#### New features (relative to Macaw)

[](#new-features-relative-to-macaw-)

- Named params (e.g. `@user:alpha`)
- Optional route segments and params, param defaults
- Route-group prefixing
- Param regex &amp; aliases can be broken out for readability
- Short defs for multi-method routes
- Named routes and reverse routing, custom dispatch
- Per-route fall-through control (Macaw has only global)
- Route compilation cache, import/export
- Utility methods for `is_ajax`, `is_https` and `redirect`
- Modified and added regex aliases

#### Other PHP routers

[](#other-php-routers)

- Macaw -
- Phroute -
- Klein -
- FastRoute -
- Pux -
- AltoRouter -
- Aura -
- mu -

\* As with any router, speed will depend on: route quantity &amp; complexity, numbers of params, whether caching is used, server hardware, PHP version, opcode caching.

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity27

Early-stage or recently created project

 Bus Factor1

Top contributor holds 93.8% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/0f3ee2ad9a6b416ed0b4072361579c759a0187addbbeb9dc4ef607c4d8e51030?d=identicon)[leeoniya](/maintainers/leeoniya)

---

Top Contributors

[![leeoniya](https://avatars.githubusercontent.com/u/43234?v=4)](https://github.com/leeoniya "leeoniya (15 commits)")[![EduVillas](https://avatars.githubusercontent.com/u/5814770?v=4)](https://github.com/EduVillas "EduVillas (1 commits)")

### Embed Badge

![Health badge](/badges/leeoniya-route66/health.svg)

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

###  Alternatives

[laravel/telescope

An elegant debug assistant for the Laravel framework.

5.2k67.8M192](/packages/laravel-telescope)[spiral/roadrunner

RoadRunner: High-performance PHP application server and process manager written in Go and powered with plugins

8.4k12.2M84](/packages/spiral-roadrunner)[nolimits4web/swiper

Most modern mobile touch slider and framework with hardware accelerated transitions

41.8k177.2k1](/packages/nolimits4web-swiper)[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k36.7M259](/packages/laravel-dusk)[laravel/prompts

Add beautiful and user-friendly forms to your command-line applications.

708181.8M596](/packages/laravel-prompts)[cakephp/chronos

A simple API extension for DateTime.

1.4k47.7M121](/packages/cakephp-chronos)

PHPackages © 2026

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