1
0
mirror of https://github.com/dannyvankooten/AltoRouter.git synced 2025-08-05 16:07:32 +02:00
Files
php-altorouter/usage/rewrite-requests.html
Danny van Kooten 6bd61a7a04 fix internal links
2023-10-09 20:14:26 +02:00

44 lines
1.4 KiB
HTML

---
title: "Rewrite all requests to AltoRouter"
layout: default
---
<h1>
<small>Using AltoRouter</small>
Rewrite all requests to AltoRouter
</h1>
<p>To use AltoRouter, you will need to rewrite all requests to a single file in which you create an instance of the AltoRouter class.</p>
<p>There are various ways to go about this, but here are examples for Apache and Nginx.</p>
<h4>Apache <code>.htaccess</code></h4>
{% highlight apache %}
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
{% endhighlight %}
<h4>Nginx <code>nginx.conf</code></h4>
{% highlight nginx %}
try_files $uri /index.php;
{% endhighlight %}
<p>All requests are now handled by the same file. In that file, you create an <code>AltoRouter</code> instance.</p>
{% highlight php startinline %}
$router = new AltoRouter();
{% endhighlight %}
<p>Optionally, if your project lives in a sub-folder of your web root you use the <code>setBasePath()</code> method to set a base path.</p>
{% highlight php startinline %}
$router->setBasePath('/alto-app/');
{% endhighlight %}
<p>You are now ready to start <a href="{{ '/usage/mapping-routes.html' | relative_url }}">mapping your routes</a>.</p>
<p>
<a style="float:left;" href="{{ '/usage/install.html' | relative_url }}">&laquo; Installing AltoRouter</a>
<a style="float:right;" href="{{ '/usage/mapping-routes.html' | relative_url }}">Mapping routes &raquo;</a>
<br style="clear:both;">
</p>