URL parameters always cause the router to fail finding the right route

Hey Kirby community,

I have issues regarding the url parameters to filter content by tags, basically following the docs.

According to the toolkit docs of the param function, url parameters following the scheme key:value (e.g. /seminars/tag:categoryname) will be ignored by the router. Hence, the given url should resolve to /seminars and therefore invoke the seminars controller. Anyhow, this is not the case and this request always returns the error page. In the error page template param(‘tag’) does also not return anything.

Is there anything to configure I may have missed? Not posting any source code because I do not do anything different from the example give in the docs.

Any help is welcome :slight_smile:

Cheers
benzin

You can easily test that this should generally work with the following route:

c::set('routes', array(
array(
    'pattern' => 'test',
    'method' => 'GET',
    'action' => function() {
     
   $array = [4,5,6,7,8];

        return response::json(array(
            $array
        ));
    }
  )
));

So now if you call “example.com/test”, your output should be:

[[4,5,6,7,8]]

And if you add a tag to the URL like this: “example.com/test/tag:blue”, the result will be all the same.

So it would be helpful to know what you are trying to do and to have your router and controller codes and your folder setup. What is the purpose of your route?

That’s a neat trick indeed, thanks for that. That’ll be handy in the future.

Unfortunately, it does not return the same. If I request /test/tag:foo, all I get is the error page.

Edit:
I just tried your example code with a fresh starterkit install and it is the same behaviour.

@benzin:

Does your webserver run on Windows? Then you cannot use “:” as separator.

@anon77445132 is right, on Windows you have to use a semicolon instead of a colon.

You are correct :fearful: I have never heard of that issue before. Just testet on a linux system and it works like expected. I’ll prepare a pr for the kirby docs to put in a note.

I tested this and it works as well - it’s not as nice as a colon, though.

Thanks everyone!

I know this is an old topic, but it just caused me another 30+min figuring out why colon didn’t work…

Did you ever get around to making that PR?

@eXpl0it3r The tags cookbook article was updated quite I while ago, it uses url:paramsToString() instead of a colon. Where were you looking for that information?

Edit: I just updated the param helper docs as well.

Neither the cookbook, nor the param helper, nor the params helper effectively mention that on Windows semicolon needs to be used.

The cookbook mentiones url::paramsToString(), but when I check how to use params, I might not read beyond “Controlling the filter by URL” or wouldn’t necessarily connect the mention of “compatible with both Linux and Windows servers” that I have to use semicolon on Windows.

Your changes just now, is what I would have expected. I’d suggest to add it to params and the “Controlling the filter by URL” section in the cookbook as well. :slight_smile:

@eXpl0it3r Thanks for your hints. I just updated both instances.

1 Like