Proxy with rewrite

I want to rewrite all other not proxy path.

But I get Error during parsing: Wrong argument count or unexpected line ending after '/mysql'

How can I do ?

Note a and b is docker service, I’m using caddy in docker., {
    header / Strict-Transport-Security "max-age=31536000;"
    proxy /api a:5000 {
    proxy /mysql b:8080 {
    rewrite {
        if {path} not /api and {path} not /mysql
        to {path} /

Hi @GreatFireWall, welcome to the Caddy community.

You can’t use a full chain of logic on a single if subdirective. The syntax is if a cond b, each instance must take three arguments.

Instead, specify multiple if subdirectives.

  • if specifies a rewrite condition. Multiple ifs are AND-ed together. a and b are any string and may use request placeholders. cond is the condition, with possible values explained below.
  • if_op specifies how the ifs are evaluated; the default is and .

Thanks your guide.
And can you show me an example how to use if_op if it’s or ?

The syntax is if_op [and|or].

The rest is the same - use multiple if subdirectives. With if_op or set, the rewrite can be executed if any of the conditionals match, instead of all of the conditionals having to match.

rewrite {
    if {path} not /api 
    if {path} not /mysql
    to {path} /

Is this right ?

I’m afraid not. and is not a subdirective of rewrite. The rest looks good.

The only subdirectives you can use are regexp, ext, if, if_op, and to. Give the docs another read, specifically the syntax section:

You don’t specify between each if statement whether they’re grouped AND or OR. You simply specify all the conditions, then you can optionally specify how all of them are grouped.

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