Skip to content

Commit

Permalink
feat(caddy): use new first_exist_fallback try policy
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas committed Jan 6, 2025
1 parent 2276129 commit c2ca4db
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions caddy/caddy.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ func parsePhpServer(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error)
if indexFile != "off" {
dirRedir := false
dirIndex := "{http.request.uri.path}/" + indexFile
tryPolicy := "first_exist_fallback"

// if tryFiles wasn't overridden, use a reasonable default
if len(tryFiles) == 0 {
Expand All @@ -540,6 +541,11 @@ func parsePhpServer(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error)

dirRedir = true
} else {
if !strings.HasSuffix(tryFiles[len(tryFiles)-1], ".php") {
// use first_exist strategy if the last file is not a PHP file
tryPolicy = ""
}

for _, tf := range tryFiles {
if tf == dirIndex {
dirRedir = true
Expand Down Expand Up @@ -579,6 +585,7 @@ func parsePhpServer(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error)
rewriteMatcherSet := caddy.ModuleMap{
"file": h.JSON(fileserver.MatchFile{
TryFiles: tryFiles,
TryPolicy: tryPolicy,
SplitPath: extensions,
}),
}
Expand Down

0 comments on commit c2ca4db

Please sign in to comment.