@@ -448,7 +448,7 @@ func parsePhpServer(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error)
448448 indexFile := "index.php"
449449
450450 // set up for explicitly overriding try_files
451- tryFiles := []string {}
451+ var tryFiles []string
452452
453453 // if the user specified a matcher token, use that
454454 // matcher in a route that wraps both of our routes;
@@ -546,31 +546,52 @@ func parsePhpServer(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error)
546546
547547 // if the index is turned off, we skip the redirect and try_files
548548 if indexFile != "off" {
549- // route to redirect to canonical path if index PHP file
550- redirMatcherSet := caddy.ModuleMap {
551- "file" : h .JSON (fileserver.MatchFile {
552- TryFiles : []string {"{http.request.uri.path}/" + indexFile },
553- }),
554- "not" : h .JSON (caddyhttp.MatchNot {
555- MatcherSetsRaw : []caddy.ModuleMap {
556- {
557- "path" : h .JSON (caddyhttp.MatchPath {"*/" }),
558- },
559- },
560- }),
561- }
562- redirHandler := caddyhttp.StaticResponse {
563- StatusCode : caddyhttp .WeakString (strconv .Itoa (http .StatusPermanentRedirect )),
564- Headers : http.Header {"Location" : []string {"{http.request.orig_uri.path}/" }},
565- }
566- redirRoute := caddyhttp.Route {
567- MatcherSetsRaw : []caddy.ModuleMap {redirMatcherSet },
568- HandlersRaw : []json.RawMessage {caddyconfig .JSONModuleObject (redirHandler , "handler" , "static_response" , nil )},
569- }
549+ dirRedir := false
550+ dirIndex := "{http.request.uri.path}/" + indexFile
570551
571552 // if tryFiles wasn't overridden, use a reasonable default
572553 if len (tryFiles ) == 0 {
573- tryFiles = []string {"{http.request.uri.path}" , "{http.request.uri.path}/" + indexFile , indexFile }
554+ if disableFsrv {
555+ tryFiles = []string {dirIndex , indexFile }
556+ } else {
557+ tryFiles = []string {"{http.request.uri.path}" , dirIndex , indexFile }
558+ }
559+
560+ dirRedir = true
561+ } else {
562+ for _ , tf := range tryFiles {
563+ if tf == dirIndex {
564+ dirRedir = true
565+
566+ break
567+ }
568+ }
569+ }
570+
571+ // route to redirect to canonical path if index PHP file
572+ if dirRedir {
573+ redirMatcherSet := caddy.ModuleMap {
574+ "file" : h .JSON (fileserver.MatchFile {
575+ TryFiles : []string {dirIndex },
576+ }),
577+ "not" : h .JSON (caddyhttp.MatchNot {
578+ MatcherSetsRaw : []caddy.ModuleMap {
579+ {
580+ "path" : h .JSON (caddyhttp.MatchPath {"*/" }),
581+ },
582+ },
583+ }),
584+ }
585+ redirHandler := caddyhttp.StaticResponse {
586+ StatusCode : caddyhttp .WeakString (strconv .Itoa (http .StatusPermanentRedirect )),
587+ Headers : http.Header {"Location" : []string {"{http.request.orig_uri.path}/" }},
588+ }
589+ redirRoute := caddyhttp.Route {
590+ MatcherSetsRaw : []caddy.ModuleMap {redirMatcherSet },
591+ HandlersRaw : []json.RawMessage {caddyconfig .JSONModuleObject (redirHandler , "handler" , "static_response" , nil )},
592+ }
593+
594+ routes = append (routes , redirRoute )
574595 }
575596
576597 // route to rewrite to PHP index file
@@ -588,7 +609,7 @@ func parsePhpServer(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error)
588609 HandlersRaw : []json.RawMessage {caddyconfig .JSONModuleObject (rewriteHandler , "handler" , "rewrite" , nil )},
589610 }
590611
591- routes = append (routes , redirRoute , rewriteRoute )
612+ routes = append (routes , rewriteRoute )
592613 }
593614
594615 // route to actually pass requests to PHP files;
0 commit comments