{"id":"2039b9a8697f7501","repo":"gohugoio/hugo","slug":"failed-to-compile-redirect-glob-q-w","errorCode":null,"errorMessage":"failed to compile Redirect glob %q: %w","messagePattern":"failed to compile Redirect glob %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/commonConfig.go","lineNumber":270,"sourceCode":"\t}\n\tfor _, h := range s.Headers {\n\t\tg, err := glob.Compile(h.For)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to compile Headers glob %q: %w\", h.For, err)\n\t\t}\n\t\ts.compiledHeaders = append(s.compiledHeaders, g)\n\t}\n\tfor _, r := range s.Redirects {\n\t\tif r.From == \"\" && r.FromRe == \"\" {\n\t\t\treturn fmt.Errorf(\"redirects must have either From or FromRe set\")\n\t\t}\n\t\trd := redirect{\n\t\t\theaders: make(map[string]glob.Glob),\n\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)","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/config/commonConfig.go#L252-L288","documentation":"Raised by Server.CompileConfig when the `from` glob of a `[[server.redirects]]` entry fails glob.Compile. The `from` field is matched against request paths with gobwas/glob, so invalid glob syntax aborts config loading with this error quoting the pattern.","triggerScenarios":"Running `hugo server` with a redirect like `from = \"/[old\"` (unbalanced character class), `from = \"/{a,b\"` (unclosed alternation), or regexp syntax such as `from = \"/old/(.*)\"` intended for `fromRe` placed in `from` — parenthesized groups can still compile as glob but bracket errors will not.","commonSituations":"Confusing `from` (glob) with `fromRe` (regexp) — putting regexp capture groups in `from`; copying redirect rules from Netlify/Cloudflare that use different pattern languages; typos in brace groups when handling multiple legacy paths.","solutions":["If the pattern is a regexp, move it to `fromRe` instead of `from`.","Fix the glob syntax quoted in the error — balance `[]`/`{}` and use `*`/`**` wildcards.","Simplify to a plain glob like `from = \"/old/**\"` and use `to = \"/new/\"`."],"exampleFix":"# before (hugo.toml)\n[[server.redirects]]\nfrom = \"/old/[ab\"\nto = \"/new/\"\n\n# after\n[[server.redirects]]\nfrom = \"/old/[ab]*\"\nto = \"/new/\"","handlingStrategy":"validation","validationCode":"import \"github.com/gobwas/glob\"\nif r.From != \"\" {\n    if _, err := glob.Compile(r.From); err != nil {\n        return fmt.Errorf(\"redirect 'from' glob %q invalid: %w\", r.From, err)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := cfg.Server.CompileConfig(logger); err != nil {\n    // \"failed to compile Redirect glob\" names the bad pattern in %q — fix that 'from'\n    return err\n}","preventionTips":["`from` is a glob: `/old/**` style, never a regexp — use `fromRe` for regexps","Escape or avoid stray `[`/`{` characters in glob patterns","Smoke-test redirects with `hugo server` before deploying"],"tags":["hugo","config","server","redirects","glob"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}