{"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/8a468df065a75c1c7cf9f6850f32148746590ea5/config/commonConfig.go#L266-L302","documentation":"Raised by Server.CompileConfig when a value in a redirect's `fromHeaders` map fails glob.Compile. `fromHeaders` lets a redirect match only when request headers match given glob patterns (used e.g. for htmx-aware routing in `hugo server`); each header value pattern must be a valid glob.","triggerScenarios":"A `[[server.redirects]]` entry with a `[server.redirects.fromHeaders]` table whose value is malformed glob syntax, e.g. `HX-Request = \"[tru\"` (unbalanced bracket) or an unclosed brace group in the header-value pattern.","commonSituations":"Setting up htmx or content-negotiation redirects in the dev server and writing regexp syntax in header-value patterns; typos in patterns like `{true,1}` missing the closing brace; copying examples with smart quotes from docs or blogs.","solutions":["Fix the header-value glob quoted in the error under `fromHeaders` — balance brackets/braces.","Use exact strings or simple globs (`*`) for header values, e.g. `HX-Request = \"true\"`.","Remember header-value patterns are globs, not regexps — rewrite regexp constructs accordingly."],"exampleFix":"# before (hugo.toml)\n[[server.redirects]]\nfrom = \"/**\"\nto = \"/partials{path}\"\n[server.redirects.fromHeaders]\nHX-Request = \"{true\"\n\n# after\n[[server.redirects]]\nfrom = \"/**\"\nto = \"/partials{path}\"\n[server.redirects.fromHeaders]\nHX-Request = \"true\"","handlingStrategy":"validation","validationCode":"import \"github.com/gobwas/glob\"\nfor _, h := range r.Headers { // header keys on a redirect are globs\n    if _, err := glob.Compile(h.For); err != nil {\n        return fmt.Errorf(\"redirect header glob %q invalid: %w\", h.For, err)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := cfg.Server.CompileConfig(logger); err != nil {\n    // \"failed to compile Redirect header glob\" — a header matcher on a redirect entry is malformed\n    return err\n}","preventionTips":["Header matchers attached to redirects are globs, same syntax as [server.headers].for","Reuse an already-working glob from your headers config instead of hand-writing a new variant","Validate the whole server block with a local `hugo server` run after any redirect/header edit"],"tags":["hugo","config","server","redirects","headers","glob"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}