{"record":{"id":"e65980669986d612","repo":"caddyserver/caddy","slug":"path-regexp-find-cannot-be-empty","errorCode":null,"errorMessage":"path_regexp find cannot be empty","messagePattern":"path_regexp find cannot be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/caddyhttp/rewrite/rewrite.go","lineNumber":112,"sourceCode":"\n\tlogger *zap.Logger\n}\n\n// CaddyModule returns the Caddy module information.\nfunc (Rewrite) CaddyModule() caddy.ModuleInfo {\n\treturn caddy.ModuleInfo{\n\t\tID:  \"http.handlers.rewrite\",\n\t\tNew: func() caddy.Module { return new(Rewrite) },\n\t}\n}\n\n// Provision sets up rewr.\nfunc (rewr *Rewrite) Provision(ctx caddy.Context) error {\n\trewr.logger = ctx.Logger()\n\n\tfor i, rep := range rewr.PathRegexp {\n\t\tif rep.Find == \"\" {\n\t\t\treturn fmt.Errorf(\"path_regexp find cannot be empty\")\n\t\t}\n\t\tre, err := regexp.Compile(rep.Find)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"compiling regular expression %d: %v\", i, err)\n\t\t}\n\t\trep.re = re\n\t}\n\tif rewr.Query != nil {\n\t\tfor _, replacementOp := range rewr.Query.Replace {\n\t\t\terr := replacementOp.Provision(ctx)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"compiling regular expression %s in query rewrite replace operation: %v\", replacementOp.SearchRegexp, err)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn nil\n}","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/modules/caddyhttp/rewrite/rewrite.go#L94-L130","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Set a non-empty regex in the 'find' field of every path_regexp entry","Delete the empty path_regexp entry if it was accidental","If the regex comes from an environment variable, verify it is set and non-empty before loading Caddy","Run 'caddy validate --config <file>' to catch this before (re)starting the server"],"exampleFix":"// before (JSON)\n\"rewrite\": { \"path_regexp\": [{ \"find\": \"\", \"replace\": \"/new\" }] }\n\n// after\n\"rewrite\": { \"path_regexp\": [{ \"find\": \"/old.*\", \"replace\": \"/new\" }] }","handlingStrategy":"validation","validationCode":"for _, rep := range rewriteCfg.PathRegexp {\n    if rep.Find == \"\" {\n        return fmt.Errorf(\"path_regexp entry with empty find: %+v\", rep)\n    }\n}\n// or simply: caddy validate --config /etc/caddy/Caddyfile","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run 'caddy validate' in CI for every config change","Never template a regex from an env var without asserting it is non-empty","Lint JSON configs against Caddy's JSON schema before deploy"],"tags":["caddy","config","rewrite","regex","provisioning"],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}