diff --git a/modules/caddyhttp/reverseproxy/fastcgi/caddyfile.go b/modules/caddyhttp/reverseproxy/fastcgi/caddyfile.go index 0ba1197fd..b2350457b 100644 --- a/modules/caddyhttp/reverseproxy/fastcgi/caddyfile.go +++ b/modules/caddyhttp/reverseproxy/fastcgi/caddyfile.go @@ -310,25 +310,24 @@ func parsePHPFastCGI(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error // if the index is turned off, we skip the redirect and try_files if indexFile != "off" { - var disableDirRedir bool + dirRedir := false + dirIndex := "{http.request.uri.path}/" + indexFile // if tryFiles wasn't overridden, use a reasonable default if len(tryFiles) == 0 { - tryFiles = []string{"{http.request.uri.path}", "{http.request.uri.path}/" + indexFile, indexFile} + tryFiles = []string{"{http.request.uri.path}", dirIndex, indexFile} + dirRedir = true } else { - indexPattern := "{http.request.uri.path}/" + indexFile - disableDirRedir = true - for _, tf := range tryFiles { - if tf == indexPattern { - disableDirRedir = false + if tf == dirIndex { + dirRedir = true break } } } - if !disableDirRedir { + if dirRedir { // route to redirect to canonical path if index PHP file redirMatcherSet := caddy.ModuleMap{ "file": h.JSON(fileserver.MatchFile{