# Troubleshooting routes

**URL:** <https://forum.getkirby.com/t/troubleshooting-routes/25784>\
**Category:** Questions\
**Tags:** v3\
**Created:** [June 22, 2022, 9:27am UTC](https://forum.getkirby.com/t/troubleshooting-routes/25784 "2022-06-22T09:27:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![plagasul](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/plagasul/32/4199_2.png) [@plagasul](https://forum.getkirby.com/u/plagasul)\
**Post date:** [June 22, 2022, 9:27am UTC](https://forum.getkirby.com/t/troubleshooting-routes/25784/1 "2022-06-22T09:27:35Z")

</div>

I am always having problems with writing the right routes. I am usually getting 404’s without understanding exactly why, and kind of finding the route via trial and error.

For example, considering I have `<body data-homeurl="<?= $site->url() ?>">` see this simplified jquery ajax call:

```auto
$.ajax({
  type: "POST",
  url: $("body").data("homeurl") + "/pop-artwork",
  data: {
    id: id,
    all_ids: all_ids,
  },
  success: function (res) {
    res = JSON.parse(res);
    $("#modal-1 .modal-body").html(res);
  },
  error: function (jqXHR, exception) {
    console.log(jqXHR);
  },
});

```

In my localhost, this is pointing to:

`http://localhost/~jaume/dev/nb/en/pop-artwork`

And this is my attempt at a route to match that url

```auto
[
    'pattern' => '(:any)/pop-artwork',
    'action' => function () {
        $id = get('id');
        $all_ids = get('all_ids');
        try {
            return json_encode(snippet('pop-artwork', array('id' => $id, 'all_ids' => $all_ids), true));
        } catch (Exception $ex) {
            return $ex->getMessage();
        }
    }
],     

```

That results in a 404

I’ve also tried the following patterns, that as far as I understand, should work, but return 404 as well

```auto
'(en|es|ca)/pop-artwork'
'(:any)/(en|es|ca)/pop-artwork'
'(:all)pop-artwork'

```

So, is there any way to produce a list of the urls a route should match to via PHP?

And, in general what am I missing here?

Thank you

---

<div class="post-metadata">

**Author:** ![moonwalk](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@moonwalk](https://forum.getkirby.com/u/moonwalk)\
**Post date:** [June 22, 2022, 9:56am UTC](https://forum.getkirby.com/t/troubleshooting-routes/25784/2 "2022-06-22T09:56:27Z")

</div>

> [@plagasul](#):
>
> ` 'pattern' => '(:any)/pop-artwork',`

The routes are always based on the base site url, so in this case, should be just `'pattern' => 'pop-artwork', but since it's a multi-language site, set the language scope as well (in this case to`\*`):

> **[Routing](https://getkirby.com/docs/guide/routing#multi-language-setup__language-scope)**
>
> Use Kirby's router to modify URLs or provide extra functionality when the user calls an given URI pattern.

---

<div class="post-metadata">

**Author:** ![plagasul](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/plagasul/32/4199_2.png) [@plagasul](https://forum.getkirby.com/u/plagasul)\
**Post date:** [June 22, 2022, 10:06am UTC](https://forum.getkirby.com/t/troubleshooting-routes/25784/3 "2022-06-22T10:06:39Z")

</div>

Thank you,

This does not work either:

```auto
...
'pattern' => 'pop-artwork',
'language' => '*',
'action' => function () {
...

```

Also, I assumed language was only needed if I wanted to render a page, while I am returning a snippet here.

---

<div class="post-metadata">

**Author:** ![plagasul](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/plagasul/32/4199_2.png) [@plagasul](https://forum.getkirby.com/u/plagasul)\
**Post date:** [June 22, 2022, 11:02am UTC](https://forum.getkirby.com/t/troubleshooting-routes/25784/4 "2022-06-22T11:02:40Z")

</div>

Ok, in this case, as I was POSTing to the route, it seems I was missing the method in the route code, so:

```
        [
            'pattern' => '(:any)/pop-artwork',
            'method' => 'POST',
            'action' => function () {
                $id = get('id');
                $all_ids = get('all_ids');
                try {
                    return json_encode(snippet('pop-artwork', array('id' => $id, 'all_ids' => $all_ids), true));
                } catch (Exception $ex) {
                    return $ex->getMessage();
                }
            }
        ], 

```

It also works with the pattern `(:all)/pop-artwork` but not with `pop-artwork` solely.

Also, I found a way to troubleshoot the route is to change method to GET, then manually hitting the expected urls in the browser.

Cheers!
