# Routing Issue "Page Not Found"

**URL:** <https://discourse.slimframework.com/t/routing-issue-page-not-found/1009>\
**Category:** Questions\
**Created:** [December 18, 2016, 9:04pm UTC](https://discourse.slimframework.com/t/routing-issue-page-not-found/1009 "2016-12-18T21:04:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![qkzoo](https://avatars.discourse-cdn.com/v4/letter/q/839c29/32.png) [@qkzoo](https://discourse.slimframework.com/u/qkzoo)\
**Post date:** [December 18, 2016, 9:04pm UTC](https://discourse.slimframework.com/t/routing-issue-page-not-found/1009/1 "2016-12-18T21:04:24Z")

</div>

I’m learning on the fly here, Php and the Slim Framework. I’m having an issue with the routing.

This works just fine:

```
11 // add new Route 
12 $app->get("/", function () {
13 echo "<h1>Hello Slim World</h1>";
14 });
15 
16 $app->get('/hello/{name}', function (Request $request, Response $response) {
17 $name = $request->getAttribute('name');
18 $response->getBody()->write("Hello, $name");
19 
20 return $response;
21 });

```

But this is not working, as in it returns a Page Not Found error:

```
     // GET http://myserver.net/api/test?id=1
23 // Get a single user by id
24 $app->get('/test/:id', function (Request $request, Response $response) {
25 echo "HELLOOWWWWWWWW";
26 });

```

Any suggestions what I may be doing wrong? I’m using PHP 5.6 and Apache 2.4.10 on Raspbian.

---

<div class="post-metadata">

**Author:** ![tflight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/tflight/32/1205_2.png) [@tflight](https://discourse.slimframework.com/u/tflight)\
**Post date:** [December 18, 2016, 9:16pm UTC](https://discourse.slimframework.com/t/routing-issue-page-not-found/1009/2 "2016-12-18T21:16:15Z")

</div>

In your GET request you have a path that includes `/api` but that isn’t represented in your route definition, so that is where it likely isn’t matching based on what you’ve shown.

---

<div class="post-metadata">

**Author:** ![qkzoo](https://avatars.discourse-cdn.com/v4/letter/q/839c29/32.png) [@qkzoo](https://discourse.slimframework.com/u/qkzoo)\
**Post date:** [December 18, 2016, 9:24pm UTC](https://discourse.slimframework.com/t/routing-issue-page-not-found/1009/4 "2016-12-18T21:24:18Z")

</div>

I have altered the route to include the working directory just to test it out, but still keep getting the Page Not Found error. Also, the routes that are in this format:

```
// GET http://myserver.net/api/hello/bob
$app->get('/hello/{name}', function (Request $request, Response $response) {

```

…work just fine as they are, but if I modify them as you suggested they no longer work.

---

<div class="post-metadata">

**Author:** ![tflight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/tflight/32/1205_2.png) [@tflight](https://discourse.slimframework.com/u/tflight)\
**Post date:** [December 18, 2016, 11:07pm UTC](https://discourse.slimframework.com/t/routing-issue-page-not-found/1009/5 "2016-12-18T23:07:20Z")

</div>

Ah, okay so your `index.php` is within `/api`, that is helpful to know. 🙂

Your route includes a slash after `test` but your get request doesn’t have that. Also, you’d typically get your query parameters from the request object.

```php
/// GET http://myserver.net/api/test?id=1 where index.php is within api/
$app->get('/test', function ($request, $response) {
    $params = $request->getQueryParams();
    return $response->write("Hello " . var_dump($params));
});

```

---

<div class="post-metadata">

**Author:** ![qkzoo](https://avatars.discourse-cdn.com/v4/letter/q/839c29/32.png) [@qkzoo](https://discourse.slimframework.com/u/qkzoo)\
**Post date:** [December 20, 2016, 1:57am UTC](https://discourse.slimframework.com/t/routing-issue-page-not-found/1009/6 "2016-12-20T01:57:40Z")

</div>

This method **did** work for my routing function. Any idea why the `:id` part doesn’t work as in the tutorial? I tried eliminating the slash but still no success. So so far, eliminating the query params from the routing definition gets me back on track, it just doesn’t track with all the tutorials.

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![tflight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/tflight/32/1205_2.png) [@tflight](https://discourse.slimframework.com/u/tflight)\
**Post date:** [December 20, 2016, 2:16pm UTC](https://discourse.slimframework.com/t/routing-issue-page-not-found/1009/7 "2016-12-20T14:16:55Z")

</div>

I’m not sure if you might be confusing route placeholders with query parameters. Or in other words you might be confusing the path versus the query string. If we look at a URL like this:

`http://example.com/2016/12/20/news?sort=desc`

Then in this case `2016`, `12`, `20`, and `tags` are (probably) route placeholders (path) you will need to match in your route definition while `sort` is a query parameter (from the query string) with a value of `desc`.

```php
$app->get('/{year}/{month}/{day}/{tag}', function ($request, $response, $args) {
    // responds to URLs like http://example.com/2016/12/20/tags?sort=desc
    // in reality you'd likely want to use regular expression matching for numeric and length:
    // https://www.slimframework.com/docs/objects/router.html#regular-expression-matching

    $year = $args['year']; // = 2016
    $month = $args['month']; // = 12
    $day = $args['day']; // = 20
    $tag = $args['tag']; // = news

    $sort = $request->getQueryParam('sort', $default = 'asc'); // = desc if provided, asc otherwise

    return $response;
});

```

In the tutorial, the `id` is a route placeholder not a query parameter.
