{"id":"adc999e39a9d1e47","repo":"gohugoio/hugo","slug":"stopped-after-10-redirects","errorCode":null,"errorMessage":"stopped after 10 redirects","messagePattern":"stopped after 10 redirects","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/resource_factories/create/create.go","lineNumber":106,"sourceCode":"\thttpTimeout := 2 * time.Minute // Need to cover retries.\n\tif httpTimeout < (rs.Cfg.Timeout() + 30*time.Second) {\n\t\thttpTimeout = rs.Cfg.Timeout() + 30*time.Second\n\t}\n\n\treturn &Client{\n\t\trs:                    rs,\n\t\thttpCacheConfig:       httpCacheConfig,\n\t\tresourceIDDispatcher:  resourceIDDispatcher,\n\t\tremoteResourceChecker: remoteResourceChecker,\n\t\tremoteResourceLogger:  rs.Logger.InfoCommand(\"remote\"),\n\t\thttpClient: &http.Client{\n\t\t\tTimeout: httpTimeout,\n\t\t\tCheckRedirect: func(req *http.Request, via []*http.Request) error {\n\t\t\t\tif err := rs.ExecHelper.Sec().CheckAllowedHTTPURL(req.URL.String()); err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t\tif len(via) >= 10 {\n\t\t\t\t\treturn errors.New(\"stopped after 10 redirects\")\n\t\t\t\t}\n\t\t\t\treturn nil\n\t\t\t},\n\t\t\tTransport: &httpcache.Transport{\n\t\t\t\tCache: fileCache.AsHTTPCache(),\n\t\t\t\tCacheKey: func(req *http.Request) string {\n\t\t\t\t\treturn resourceIDDispatcher.Get(req.Context())\n\t\t\t\t},\n\t\t\t\tAround: func(req *http.Request, key string) func() {\n\t\t\t\t\treturn fileCache.NamedLock(key)\n\t\t\t\t},\n\t\t\t\tAlwaysUseCachedResponse: func(req *http.Request, key string) bool {\n\t\t\t\t\treturn !httpCacheConfig.For(req.URL.String())\n\t\t\t\t},\n\t\t\t\tShouldCache: func(req *http.Request, resp *http.Response, key string) bool {\n\t\t\t\t\treturn shouldCache(resp.StatusCode)\n\t\t\t\t},\n\t\t\t\tCanStore: func(reqCacheControl, respCacheControl httpcache.CacheControl) (canStore bool) {","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/resources/resource_factories/create/create.go#L88-L124","documentation":"Returned by the CheckRedirect hook of the HTTP client Hugo uses for remote resources (resources.GetRemote and remote data fetches). After 10 redirect hops the client aborts, mirroring Go's default policy, to prevent infinite redirect loops when fetching remote content.","triggerScenarios":"`resources.GetRemote \"https://...\"` (or other remote resource fetches) where the server responds with a chain of 10+ 3xx redirects — typically a redirect loop (A→B→A) or a long http→https→www→CDN chain.","commonSituations":"URLs behind auth walls that bounce between login pages, misconfigured CDN/hosting redirect rules, fetching an http:// URL that ping-pongs with https, or shortened/tracking URLs that chain many hops.","solutions":["Fetch the final URL directly — resolve the chain with `curl -IL <url>` and use the last location","Fix the redirect loop on the server/CDN configuration if you control it","Use https:// and the canonical host (with/without www) to skip unnecessary hops"],"exampleFix":"// before\n{{ $r := resources.GetRemote \"http://short.link/abc\" }}\n// after (use the resolved final URL)\n{{ $r := resources.GetRemote \"https://cdn.example.com/data.json\" }}","handlingStrategy":"retry","validationCode":"{{ $url := \"https://example.com/api\" }}{{/* prefer final URLs, not shortener/redirect chains */}}","typeGuard":null,"tryCatchPattern":"{{ with try (resources.GetRemote $url) }}{{ with .Err }}{{ warnf \"remote fetch failed: %s\" . }}{{ else }}{{ with .Value }}...{{ end }}{{ end }}{{ end }}","preventionTips":["Use the final resolved URL instead of URLs behind long redirect chains (curl -sIL to inspect the chain first)","Check .Err on resources.GetRemote results rather than assuming success","Beware redirect loops caused by missing trailing slashes or http→https→http bounces","Cache remote resources (cacheDir / getresource cache config) so transient redirect issues don't break every build"],"tags":["hugo","network","http","redirects","remote-resources"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}