/api/ to the servers as /v2/, hide the Server header, add a
header for one country. You set them in the route dialog, with no middleware to write.
Every proxy kind takes them. DNZ Proxy runs all of them; Traefik and Caddy get
what they can express, and DNZ tells you, rule by rule, what one of them can’t run before you save.
Add a rule
1
Open the route
On the proxy’s page, open the route (Routes → the route).
2
Switch on Rules
Under Redirects and rewrites, switch on Rules. The first rule opens.
3
Say when
Every request, All of these or Any of these, then the conditions: what to look at
(path, query parameter, header, method, country, visitor address, hostname), how (is, starts
with, matches…) and the values.
4
Say what to do
Redirect, Rewrite, Request header or Response header, and fill in the fields.
The rule’s line reads it back in plain words: If the path starts with /old/, redirect to
https://shop.example.com/new/{rest} (301).
5
Save
Add more rules with Add rule; drag one by its handle (or use the arrows) to change the order.
The Routes list shows Rules · 3 on the route.
Conditions
A condition can take several values: any of them matches. Case never matters. With no condition a
rule acts on every request.
Actions
Placeholders
A redirect address and a rewrite’s path and query can hold:
For example, path starts with
/blog/ → Redirect to https://news.example.com/{rest} moves
a whole section, and path matches ^/p/([0-9]+)$ → Rewrite to /post.php with the query
id={1} serves short links from an old app.
Order
Rules run from the top down, and every rule whose conditions hold acts: one can rewrite the path, the next set a header. A redirect answers right away, so the rules below it don’t run. A rule sees the request as the rules above left it: after a rewrite to/v2/…, a later “path starts with
/v2/” holds.
The rules come after the route’s access checks (address list, firewalls, the browser check, the
waiting room, rate limit, password, sign-in), upload limits and custom headers, and before the cache.
So a redirect only reaches visitors who got in.
On Traefik and Caddy
Traefik gets each rule as one of its own middlewares (
redirectRegex, replacePathRegex,
headers), with the path and hostname checks folded into the redirect’s expression; Caddy gets
routes with matchers. A rule a proxy can’t run is refused with its number and why, for example
rule 2 for Traefik: Traefik can’t tell a visitor’s country; DNZ Proxy and Caddy can. The route
dialog shows it under the rule, so nothing is saved half done.
What it costs
A route without rules has nothing extra to run. With rules, a DNZ Proxy checks each rule’s conditions and runs the actions that apply: on one CPU, five rules that don’t hold cost a visit about 3 µs (−1.8% requests a second), four rules that act about 6 µs (−5%), with no extra memory. See Benchmarks.From the terminal and assistants
set_route_rules (see AI assistants).