V2 rewrite syntax

Just upgraded from v2.0.0 to v2.2.0 and I am trying to get my head around the new rewrite V2 syntax.

That syntax has apparently changed in a more condensed way in v2.2.0. Is that new syntax more “canonical” and is it here to stay or should I stick with the “old” v2.0.0 syntax? Just curious.

sample URI to rewrite

from /bird-cards/foo_bar to /bird-cards/foo-bar

working in v2.0.0 and above

@underscore {
	path_regexp u ^/bird-cards/([^_]+)_(.+)$
}
rewrite @underscore /bird-cards/{http.regexp.u.1}-{http.regexp.u.2}

only works in v2.2.0 (and maybe in v2.1.0, not tested)

@underscore {
	path_regexp u ^/bird-cards/([^_]+)_(.+)$
}
rewrite @underscore /bird-cards/{re.u.1}-{re.u.2}

or, even shorter

@underscore path_regexp u ^/bird-cards/([^_]+)_(.+)$
rewrite @underscore /bird-cards/{re.u.1}-{re.u.2}

Caddy 2.1 made named single-matcher sets one liners:

@underscore {
	path_regexp u ^/bird-cards/([^_]+)_(.+)$
}

can now be:

@underscore path_regexp u ^/bird-cards/([^_]+)_(.+)$

At about the same time, we also introduced more shorthand placeholders into the Caddyfile for http.regexp so it can be just re.

Just little quality-of-life improvements.

1 Like

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