gohugoio/hugo · error
failed to compile Redirect glob %q: %w
Error message
failed to compile Redirect glob %q: %w
What it means
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.
Source
Thrown at config/commonConfig.go:270
}
for _, h := range s.Headers {
g, err := glob.Compile(h.For)
if err != nil {
return fmt.Errorf("failed to compile Headers glob %q: %w", h.For, err)
}
s.compiledHeaders = append(s.compiledHeaders, g)
}
for _, r := range s.Redirects {
if r.From == "" && r.FromRe == "" {
return fmt.Errorf("redirects must have either From or FromRe set")
}
rd := redirect{
headers: make(map[string]glob.Glob),
}
if r.From != "" {
g, err := glob.Compile(r.From)
if err != nil {
return fmt.Errorf("failed to compile Redirect glob %q: %w", r.From, err)
}
rd.from = g
}
if r.FromRe != "" {
re, err := regexp.Compile(r.FromRe)
if err != nil {
return fmt.Errorf("failed to compile Redirect regexp %q: %w", r.FromRe, err)
}
rd.fromRe = re
}
for k, v := range r.FromHeaders {
g, err := glob.Compile(v)
if err != nil {
return fmt.Errorf("failed to compile Redirect header glob %q: %w", v, err)
}
rd.headers[k] = g
}
s.compiledRedirects = append(s.compiledRedirects, rd)View on GitHub ↗ (pinned to 8a468df065)
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/"`.
Example fix
# before (hugo.toml) [[server.redirects]] from = "/old/[ab" to = "/new/" # after [[server.redirects]] from = "/old/[ab]*" to = "/new/"
Defensive patterns
Strategy: validation
Validate before calling
import "github.com/gobwas/glob"
if r.From != "" {
if _, err := glob.Compile(r.From); err != nil {
return fmt.Errorf("redirect 'from' glob %q invalid: %w", r.From, err)
}
} Try / catch
if err := cfg.Server.CompileConfig(logger); err != nil {
// "failed to compile Redirect glob" names the bad pattern in %q — fix that 'from'
return err
} Prevention
- `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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- failed to compile Redirect header glob %q: %w
- failed to compile Headers glob %q: %w
- redirects must have either From or FromRe set
- failed to compile Redirect regexp %q: %w
- language %q not found
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/2039b9a8697f7501.json.
Report an issue: GitHub ↗.