Path wildcard matcher that matches with and without slash?

I’m reading Request matchers (Caddyfile) — Caddy Documentation and I wonder, if I want to match /api and /api/items but I do not want to match /apineapple, do I have to write two lines like

@my-matcher {
  path /api
  path /api/*
}

or is there a shorter way?

1 Like

I think that’s the way to do it (without a regex) :+1: To me it’s very clear and makes sense.

Shorter one-line syntax:

@matcher path /api /api/*

I had suggested an alternate syntax some time ago, i.e. /api/*? but Matt wasn’t a fan :sweat_smile:

1 Like

Oh yeah, forgot the one-line thing.

I still don’t like the question mark :slight_smile:

1 Like

I have to say, I don’t like the question mark either, because my brain reads it like a regex where * is not special, so it becomes “/api/ or /api/something” which is not what it’s supposed to mean (that would be “/api or /api/something”).

So yeah, the one-liner is fine for me.

By the way, I had trouble finding in the docs whether

@my-matcher {
  path a b
}

is equivalent to

@my-matcher {
  path a
  path b
}

(The answer is yes.)

It does say

Multiple paths will be OR’ed together.

but that could very well apply only to multiple given paths after a single path keyword.

1 Like

Good q, they get combined, so yeah they are identical. :+1:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.