AltoRouter

PHP5.3+ Routing Class. Supports REST, dynamic and reversed routing.

View the Project on GitHub dannyvankooten/AltoRouter

Download ZIP View on GitHub

Using AltoRouter Rewrite all requests to AltoRouter

To use AltoRouter, you will need to rewrite all requests to a single file in which you create an instance of the AltoRouter class.

There are various ways to go about this, but here are examples for Apache and Nginx.

Apache .htaccess

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

Nginx nginx.conf

try_files $uri /index.php;

All requests are now handled by the same file. In that file, you create an AltoRouter instance.

$router = new AltoRouter();

Optionally, if your project lives in a sub-folder of your web root you use the setBasePath() method to set a base path.

$router->setBasePath('/alto-app/');

You are now ready to start mapping your routes.

« Installing AltoRouter Mapping routes »