PHPackages                             erlendellingsen/flex-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. erlendellingsen/flex-router

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

erlendellingsen/flex-router
===========================

A small, lightweight php-router for creating clean, RESTful urls. Extremely easy to setup and configure.

1.0.0-stable(9y ago)1820MITPHP ^5.3.3 || ^7.0

Since Mar 7Compare

[ Source](https://github.com/ErlendEllingsen/flexRouter)[ Packagist](https://packagist.org/packages/erlendellingsen/flex-router)[ RSS](/packages/erlendellingsen-flex-router/feed)WikiDiscussions Synced 2w ago

READMEChangelog (2)DependenciesVersions (2)Used By (0)

[![flexRouter logo](https://camo.githubusercontent.com/b492a347cbc4cb08cdfa5129f1a51795a13b389ff9e7bbb3c1b2879fa8c515db/68747470733a2f2f692e696d6775722e636f6d2f4e3048454363612e706e67)](https://camo.githubusercontent.com/b492a347cbc4cb08cdfa5129f1a51795a13b389ff9e7bbb3c1b2879fa8c515db/68747470733a2f2f692e696d6775722e636f6d2f4e3048454363612e706e67)

[![Build Status](https://camo.githubusercontent.com/b66ec8c8efed65d985c081510b935e5f747aa7c6f43c07e48c223cdf94f46580/68747470733a2f2f7472617669732d63692e6f72672f45726c656e64456c6c696e6773656e2f666c6578526f757465722e737667)](https://travis-ci.org/ErlendEllingsen/flexRouter/)[![MIT Licence](https://camo.githubusercontent.com/fabb40ab22588a0746bb0916ed92739171bde7fb31f281c627aa588bcba62cc2/68747470733a2f2f6261646765732e66726170736f66742e636f6d2f6f732f6d69742f6d69742e7376673f763d313033)](https://opensource.org/licenses/mit-license.php)

flexRouter
==========

[](#flexrouter)

An extremely *small* and *lightweight* PHP-router for clean, RESTful urls. Extremely easy to setup and requires no configuration. Just plain dead simple routing.

Supports parameters, different HTTP-methods and wildcard urls.

What's Changed
--------------

[](#whats-changed)

As the new maintainer I tried to implement a better more robust architecture without going away from the initial goal of the router which was to work off of if based control structures.

This may change in the future as the project evolves. Below is the reworked example of how I envision you using the router in its new, unit tested, form.

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

[](#installation)

```
composer require erlendellingsen/flex-router

```

Setup
-----

[](#setup)

URL-rewrite must be enabled on the target server. This guide consists of an example on how to set it up on Apache-servers. **If you do have IIS, Nginx or other examples, then please contribute!**

Apache
------

[](#apache)

**Configuration**

- Apache-module `mod_rewrite` **must** be enabled.
- Required Apache-vhost/Directory-setting `AllowOverride all`

**.htaccess-file**

```
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*)$ index.php?path=$1 [NC,L,QSA]

```

Non-Apache
----------

[](#non-apache)

You *somehow* have to enable rewriting of urls in your web server/directory to point all requests to `index.php?path=x`. If you have somewhat idea how, but need assistance then don't hesitate to **reach out**.

If you do have an example for other web servers then please consider getting in touch. (Open an issue, a fork, or just email me). Contributions are **very much** appreciated ☺️

Usage
-----

[](#usage)

The example beneath demonstrates how to setup *flexRouter*.

```
