gohugoio/hugo · error
failed to split baseURL hostport: %w
Error message
failed to split baseURL hostport: %w
What it means
While rewriting the baseURL for serving with `--appendPort` enabled, Hugo strips any existing port from the URL's host before appending the live server port. If the host contains a `:` but `net.SplitHostPort` cannot split it, the baseURL host is malformed and server startup fails with this wrapped error.
Source
Thrown at commands/server.go:838
if err != nil {
return "", err
}
}
if useLocalhost {
if certsSet {
u.Scheme = "https"
} else if u.Scheme == "https" {
u.Scheme = "http"
}
u.Host = "localhost"
}
if c.serverAppend {
if strings.Contains(u.Host, ":") {
u.Host, _, err = net.SplitHostPort(u.Host)
if err != nil {
return "", fmt.Errorf("failed to split baseURL hostport: %w", err)
}
}
u.Host += fmt.Sprintf(":%d", port)
}
return u.String(), nil
}
func (c *serverCommand) partialReRender(urls ...string) (err error) {
defer func() {
c.errState.setWasErr(false)
}()
visited := types.NewEvictingQueue[string](len(urls))
for _, url := range urls {
visited.Add(url)
}
var h *hugolib.HugoSitesView on GitHub ↗ (pinned to 8a468df065)
Solutions
- Fix the host portion of `baseURL`: IPv6 literals must be bracketed, e.g. `http://[::1]:1313/`.
- Remove stray or duplicated colons from the configured baseURL or `--baseURL` flag value.
- Since Hugo appends the port itself when `--appendPort` is on (the default), you can omit the port from baseURL entirely.
Example fix
# before (hugo.toml) baseURL = "http://::1/" # after baseURL = "http://[::1]/"
Defensive patterns
Strategy: validation
Validate before calling
if _, _, err := net.SplitHostPort(u.Host); err != nil {
// no port present — acceptable, but make sure host isn't malformed (e.g. bad IPv6 brackets)
if strings.Contains(u.Host, ":") {
return fmt.Errorf("malformed host:port in baseURL %q: %w", baseURL, err)
}
} Prevention
- Bracket IPv6 literals in baseURL: https://[::1]:1313/
- Don't put multiple colons or an empty port (host:) in the baseURL
- Validate baseURL with url.Parse + net.SplitHostPort in wrapper tooling before launch
When it happens
Trigger: `fixURL` on a baseURL whose parsed `u.Host` contains `:` yet fails `net.SplitHostPort` — e.g. an unbracketed IPv6 address (`baseURL = "http://::1/"`), multiple colons, or a garbage host like `example.com:80:90`.
Common situations: Using IPv6 literals in `baseURL` or `-b` without square brackets (`[::1]:1313`); typos leaving a trailing/double colon in the host (`example.com::1313`); templated baseURLs in CI concatenating host and port incorrectly.
Related errors
- failed to create baseURL from %q: %s
- cannot use --renderToMemory with --destination
- failed to parse root certificate
- failed to parse certificate PEM
- failed to parse certificate: %v
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/20ed961a6eae6a11.json.
Report an issue: GitHub ↗.