Altorouter cant figure out how to route correctly PHP
<p>if you haven't used this before the link is: <a href="http://altorouter.com/" rel="nofollow">http://altorouter.com/</a></p>

<p>I am making a small application but do not require a framework, only the routing part. So I've decided to try altorouter out as it seemed quite simple. </p>

<p>I want to map certain routes to do certain things. for example:</p>

<p>www.example.com/products/ </p>

<p>this should show my products.php template and pull data from the database to populate the fields. I have got this working with the following:</p>

<pre><code>$router-&gt;map( 'GET', '/products', function() {
    require('partials/connectdb.php'); //Require Database Connection
    $pageContent = getProductsContent($conn); //prepare all the page content from database
    require __DIR__ . '/products.php'; //require the template to use
});
</code></pre>

<p>The same for all of the other standard pages, my problem is when the route can change. For example:</p>

<p>www.example.com/shoes/ </p>

<p>www.example.com/shorts/</p>

<p>www.example.com/shirts/</p>

<p>www.example.com/ties/</p>

<p>When a user goes to these routes I want to get the param 'shoes' and then while still using the products.php template, do the logic for only shoes.</p>

<p>So looking at the docs it says you can do: </p>

<p>www.example.com/[*] //which means anything.</p>

<p>However after adding this into my listed routes, it voids anything else the user trys to visit. So if they visit:</p>

<p>www.example.com/products // Like it worked before</p>

<p>It actually does the logic inside:</p>

<p>www.example.com/[*]</p>

<p>Does anyone know altorouter and can help me out please? I will paste my full page code below:</p>

<pre><code>// Site Router
$router-&gt;map( 'GET', '/', function() {
    require('partials/connectdb.php'); //Require Database Connection
    $pageContent = getHomeContent($conn);
    require __DIR__ . '/home.php';
});


$router-&gt;map( 'GET', '/products', function() {
    require('partials/connectdb.php'); //Require Database Connection
    $pageContent = getProductsContent($conn);
    require __DIR__ . '/products.php';
});


$router-&gt;map( 'GET', '/[*]', function($id) {
    require('partials/connectdb.php'); //Require Database Connection


    $test = 'this was a test';
    $pageContent = getProductsContent($conn);
    require __DIR__ . '/products.php';
});

// match current request url
$match = $router-&gt;match();

// call closure or throw 404 status
if( $match &amp;&amp; is_callable( $match['target'] ) ) {
    call_user_func_array( $match['target'], $match['params'] );
} else {
    // no route was matched
    header( $_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found');
}
</code></pre>