Check url early

I can do this:

if(str::contains($_SERVER['REQUEST_URI'], '/my-special-url')) {
  // Include some files

It would in one way be better to fetch the url with a route, but by the time I run the route it will be too late. I need to run it directly.

Is there a nicer way instead of the code above that runs directly (not a route)?

Hi Jens, what are you trying to do and where and why?

Inside the if statement I will set things with the registry. I cant set things with the registry inside the route (runs too late). Therefor I can’t use that.

I will probably use my example above as a starting point and try to improve it to get a better match in the if statement.


A very simplified example of the final result will probably look kind of like this:

    'pattern' => c::get('my.plugin.uri'),
    'action'  => function() {
      echo 'Hi Sonja!';

if(str::contains($_SERVER['REQUEST_URI'], '/' . c::get('my.plugin.uri'))) {
  $kirby->set('brick', 'header', __DIR__ . DS . 'header');
  $kirby->set('brick', 'menu', __DIR__ . DS . 'menu');


I think I found a more solid solution to matching the uri. Let me know if there are any pitfalls.

Visit like for a match:

c::set('my.plugin.test', 'my/test/uri');
$uri = str_replace(url::index() . '/', '', url::current());

if($uri == c::get('my.plugin.test') || $uri == c::get('my.plugin.test') . '/') {
  echo 'Match';