{"record":{"id":"75c02ac8169199b2","repo":"gohugoio/hugo","slug":"failed-to-compile-redirect-header-glob-q-w","errorCode":null,"errorMessage":"failed to compile Redirect header glob %q: %w","messagePattern":"failed to compile Redirect header glob %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/commonConfig.go","lineNumber":284,"sourceCode":"\t\t}\n\t\tif r.From != \"\" {\n\t\t\tg, err := glob.Compile(r.From)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to compile Redirect glob %q: %w\", r.From, err)\n\t\t\t}\n\t\t\trd.from = g\n\t\t}\n\t\tif r.FromRe != \"\" {\n\t\t\tre, err := regexp.Compile(r.FromRe)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to compile Redirect regexp %q: %w\", r.FromRe, err)\n\t\t\t}\n\t\t\trd.fromRe = re\n\t\t}\n\t\tfor k, v := range r.FromHeaders {\n\t\t\tg, err := glob.Compile(v)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to compile Redirect header glob %q: %w\", v, err)\n\t\t\t}\n\t\t\trd.headers[k] = g\n\t\t}\n\t\ts.compiledRedirects = append(s.compiledRedirects, rd)\n\t}\n\n\treturn nil\n}\n\nfunc (s *Server) MatchHeaders(pattern string) []types.KeyValueStr {\n\tif s.compiledHeaders == nil {\n\t\treturn nil\n\t}\n\n\tvar matches []types.KeyValueStr\n\n\tfor i, g := range s.compiledHeaders {\n\t\tif g.Match(pattern) {","sourceCodeStart":266,"sourceCodeEnd":302,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/config/commonConfig.go#L266-L302","documentation":"Emitted by Server.CompileConfig while compiling a redirect's `fromHeaders` map. Each header value is compiled as a glob via gobwas/glob; headers gate whether a matched redirect actually fires. If any header value's glob is malformed, the error is wrapped with that value.","triggerScenarios":"A `[[server.redirects]]` with a `fromHeaders` entry like `{ Host = \"{bad\" }` whose glob is invalid.","commonSituations":"Using regexp syntax in a header glob field; malformed brace expansion in a Host matcher.","solutions":["Use glob syntax for every `fromHeaders` value.","Balance braces/brackets; test the value in a glob tester.","Remove the header condition if not needed."],"exampleFix":"# before\n[[server.redirects]]\nfrom = \"/old/*\"\nfromHeaders = { Host = \"{bad\" }\nto = \"/new\"\n\n# after\n[[server.redirects]]\nfrom = \"/old/*\"\nfromHeaders = { Host = \"example.{com,org}\" }\nto = \"/new\"","handlingStrategy":"validation","validationCode":"python3 - <<'PY'\nimport tomllib\ncfg=tomllib.loads(open('hugo.toml').read())\nfor r in cfg.get('server',{}).get('redirects',[]):\n    for hk,hv in (r.get('fromHeaders') or {}).items():\n        assert hv.count('{')==hv.count('}') and hv.count('[')==hv.count(']'), f\"unbalanced header glob {hv!r}\"\nprint(\"redirect header globs ok\")\nPY","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use glob syntax for every fromHeaders value.","Balance braces/brackets.","Test Host matchers like `example.{com,org}` in a glob tester."],"tags":["config","server","redirects","headers","glob"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}