--- title: "Rewrite all requests to AltoRouter" layout: default ---

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

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

Nginx nginx.conf

{% highlight nginx %} try_files $uri /index.php; {% endhighlight %}

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

{% highlight php startinline %} $router = new AltoRouter(); {% endhighlight %}

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

{% highlight php startinline %} $router->setBasePath('/alto-app/'); {% endhighlight %}

You are now ready to start mapping your routes.

« Installing AltoRouter Mapping routes »