@@ -179,7 +179,7 @@ func parsePHPFastCGI(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error
179
179
indexFile := "index.php"
180
180
181
181
// set up for explicitly overriding try_files
182
- tryFiles := []string {}
182
+ var tryFiles []string
183
183
184
184
// if the user specified a matcher token, use that
185
185
// matcher in a route that wraps both of our routes;
@@ -310,31 +310,47 @@ func parsePHPFastCGI(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error
310
310
311
311
// if the index is turned off, we skip the redirect and try_files
312
312
if indexFile != "off" {
313
- // route to redirect to canonical path if index PHP file
314
- redirMatcherSet := caddy.ModuleMap {
315
- "file" : h .JSON (fileserver.MatchFile {
316
- TryFiles : []string {"{http.request.uri.path}/" + indexFile },
317
- }),
318
- "not" : h .JSON (caddyhttp.MatchNot {
319
- MatcherSetsRaw : []caddy.ModuleMap {
320
- {
321
- "path" : h .JSON (caddyhttp.MatchPath {"*/" }),
322
- },
323
- },
324
- }),
325
- }
326
- redirHandler := caddyhttp.StaticResponse {
327
- StatusCode : caddyhttp .WeakString (strconv .Itoa (http .StatusPermanentRedirect )),
328
- Headers : http.Header {"Location" : []string {"{http.request.orig_uri.path}/" }},
329
- }
330
- redirRoute := caddyhttp.Route {
331
- MatcherSetsRaw : []caddy.ModuleMap {redirMatcherSet },
332
- HandlersRaw : []json.RawMessage {caddyconfig .JSONModuleObject (redirHandler , "handler" , "static_response" , nil )},
333
- }
313
+ dirRedir := false
314
+ dirIndex := "{http.request.uri.path}/" + indexFile
334
315
335
316
// if tryFiles wasn't overridden, use a reasonable default
336
317
if len (tryFiles ) == 0 {
337
- tryFiles = []string {"{http.request.uri.path}" , "{http.request.uri.path}/" + indexFile , indexFile }
318
+ tryFiles = []string {"{http.request.uri.path}" , dirIndex , indexFile }
319
+ dirRedir = true
320
+ } else {
321
+ for _ , tf := range tryFiles {
322
+ if tf == dirIndex {
323
+ dirRedir = true
324
+
325
+ break
326
+ }
327
+ }
328
+ }
329
+
330
+ if dirRedir {
331
+ // route to redirect to canonical path if index PHP file
332
+ redirMatcherSet := caddy.ModuleMap {
333
+ "file" : h .JSON (fileserver.MatchFile {
334
+ TryFiles : []string {dirIndex },
335
+ }),
336
+ "not" : h .JSON (caddyhttp.MatchNot {
337
+ MatcherSetsRaw : []caddy.ModuleMap {
338
+ {
339
+ "path" : h .JSON (caddyhttp.MatchPath {"*/" }),
340
+ },
341
+ },
342
+ }),
343
+ }
344
+ redirHandler := caddyhttp.StaticResponse {
345
+ StatusCode : caddyhttp .WeakString (strconv .Itoa (http .StatusPermanentRedirect )),
346
+ Headers : http.Header {"Location" : []string {"{http.request.orig_uri.path}/" }},
347
+ }
348
+ redirRoute := caddyhttp.Route {
349
+ MatcherSetsRaw : []caddy.ModuleMap {redirMatcherSet },
350
+ HandlersRaw : []json.RawMessage {caddyconfig .JSONModuleObject (redirHandler , "handler" , "static_response" , nil )},
351
+ }
352
+
353
+ routes = append (routes , redirRoute )
338
354
}
339
355
340
356
// route to rewrite to PHP index file
@@ -352,7 +368,7 @@ func parsePHPFastCGI(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error
352
368
HandlersRaw : []json.RawMessage {caddyconfig .JSONModuleObject (rewriteHandler , "handler" , "rewrite" , nil )},
353
369
}
354
370
355
- routes = append (routes , redirRoute , rewriteRoute )
371
+ routes = append (routes , rewriteRoute )
356
372
}
357
373
358
374
// route to actually reverse proxy requests to PHP files;
0 commit comments