caddyserver/caddy · error

path_regexp find cannot be empty

Error message

path_regexp find cannot be empty

What it means

Thrown during provisioning of the rewrite handler when a path_regexp entry has an empty 'find' field. Caddy validates every PathRegexp entry at config-load time; an empty pattern is meaningless (it would match everything) and is rejected outright. This is a hard config error: the server refuses to start until the entry is fixed or removed.

Source

Thrown at modules/caddyhttp/rewrite/rewrite.go:112

	logger *zap.Logger
}

// CaddyModule returns the Caddy module information.
func (Rewrite) CaddyModule() caddy.ModuleInfo {
	return caddy.ModuleInfo{
		ID:  "http.handlers.rewrite",
		New: func() caddy.Module { return new(Rewrite) },
	}
}

// Provision sets up rewr.
func (rewr *Rewrite) Provision(ctx caddy.Context) error {
	rewr.logger = ctx.Logger()

	for i, rep := range rewr.PathRegexp {
		if rep.Find == "" {
			return fmt.Errorf("path_regexp find cannot be empty")
		}
		re, err := regexp.Compile(rep.Find)
		if err != nil {
			return fmt.Errorf("compiling regular expression %d: %v", i, err)
		}
		rep.re = re
	}
	if rewr.Query != nil {
		for _, replacementOp := range rewr.Query.Replace {
			err := replacementOp.Provision(ctx)
			if err != nil {
				return fmt.Errorf("compiling regular expression %s in query rewrite replace operation: %v", replacementOp.SearchRegexp, err)
			}
		}
	}

	return nil
}

View on GitHub (pinned to 50e54ee279)

Solutions

  1. Set a non-empty regex in the 'find' field of every path_regexp entry
  2. Delete the empty path_regexp entry if it was accidental
  3. If the regex comes from an environment variable, verify it is set and non-empty before loading Caddy
  4. Run 'caddy validate --config <file>' to catch this before (re)starting the server

Example fix

// before (JSON)
"rewrite": { "path_regexp": [{ "find": "", "replace": "/new" }] }

// after
"rewrite": { "path_regexp": [{ "find": "/old.*", "replace": "/new" }] }
Defensive patterns

Strategy: validation

Validate before calling

for _, rep := range rewriteCfg.PathRegexp {
    if rep.Find == "" {
        return fmt.Errorf("path_regexp entry with empty find: %+v", rep)
    }
}
// or simply: caddy validate --config /etc/caddy/Caddyfile

Prevention

When it happens

Trigger: A JSON config with "rewrite" -> "path_regexp": [{"find": "", "replace": "/x"}], or a Caddyfile path_regexp directive whose pattern argument is missing/empty (e.g. a variable that expanded to nothing during adaptation).

Common situations: Typos in JSON configs, templated configs where the regex placeholder is unset, or Caddyfile snippets that omit the pattern after a matcher name. Also hit when migrating configs where an env-substituted regex is empty.

Related errors


AI-assisted analysis of caddyserver/caddy@50e54ee279 (2026-08-15). Data as JSON: /api/errors/e65980669986d612. Report an issue: GitHub.