PHPackages                             dannyvankooten/php-router - 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. dannyvankooten/php-router

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

dannyvankooten/php-router
=========================

Simple PHP Router, supports REST and reverse routing.

1.2.0-alpha(9y ago)56530.4k120[5 PRs](https://github.com/dannyvankooten/PHP-Router/pulls)3MITPHPPHP ^5.3.0|^7.0

Since Feb 12Pushed 4y ago35 watchersCompare

[ Source](https://github.com/dannyvankooten/PHP-Router)[ Packagist](https://packagist.org/packages/dannyvankooten/php-router)[ Docs](https://github.com/dannyvankooten/PHP-Router)[ RSS](/packages/dannyvankooten-php-router/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (4)Versions (8)Used By (3)

PHP Router class
================

[](#php-router-class)

[![Latest Stable Version](https://camo.githubusercontent.com/c49d97c2c6c99d6c6c95dd66c44e7c87f4f47a414c0213426a4bf5c70c52dec6/68747470733a2f2f706f7365722e707567782e6f72672f64616e6e7976616e6b6f6f74656e2f7068702d726f757465722f762f737461626c65)](https://packagist.org/packages/dannyvankooten/php-router)[![Total Downloads](https://camo.githubusercontent.com/2508b580bf0846de48b98b3ec3ec4b35683c8f436b3e5a357e3bbb8c3c019157/68747470733a2f2f706f7365722e707567782e6f72672f64616e6e7976616e6b6f6f74656e2f7068702d726f757465722f646f776e6c6f616473)](https://packagist.org/packages/dannyvankooten/php-router)[![Latest Unstable Version](https://camo.githubusercontent.com/a38eb6df436233228e26d16b3eb611908a8c64a1b296dc95c20c1a2c77b58327/68747470733a2f2f706f7365722e707567782e6f72672f64616e6e7976616e6b6f6f74656e2f7068702d726f757465722f762f756e737461626c65)](https://packagist.org/packages/dannyvankooten/php-router)[![License](https://camo.githubusercontent.com/6113851391c55debb838ff1664db6cd94d68f229a9885333a881fd1d0fd1d398/68747470733a2f2f706f7365722e707567782e6f72672f64616e6e7976616e6b6f6f74656e2f7068702d726f757465722f6c6963656e7365)](https://packagist.org/packages/dannyvankooten/php-router)

A simple Rails inspired PHP router class.

- Usage of different HTTP Methods
- REST / Resourceful routing
- Reversed routing using named routes
- Dynamic URL's: use URL segments as parameters.

Authors
=======

[](#authors)

- [Danny van Kooten](https://github.com/dannyvankooten)
- [Jefersson Nathan](https://github.com/malukenho)

Easy to install with **composer**
=================================

[](#easy-to-install-with-composer)

```
$ composer require dannyvankooten/php-router
```

Usage
-----

[](#usage)

### Friendly URL

[](#friendly-url)

Create a simple .htaccess file on your root directory if you're using Apache with mod\_rewrite enabled.

```
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)$ index.php [NC,L]
```

If you're using nginx, setup your server section as following:

```
server {
	listen 80;
	server_name mydevsite.dev;
	root /var/www/mydevsite/public;

	index index.php;

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

	location ~ \.php$ {
		fastcgi_split_path_info ^(.+\.php)(/.+)$;
		# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

		# With php5-fpm:
		fastcgi_pass unix:/var/run/php5-fpm.sock;
		fastcgi_index index.php;
		include fastcgi.conf;
		fastcgi_intercept_errors on;
	}
}
```

This is a simple example of routers in action

```
