diff --git a/caddyhttp/rewrite/to.go b/caddyhttp/rewrite/to.go index 75f69400..5371920d 100644 --- a/caddyhttp/rewrite/to.go +++ b/caddyhttp/rewrite/to.go @@ -28,17 +28,13 @@ func To(fs http.FileSystem, r *http.Request, to string, replacer httpserver.Repl query = tparts[1] } + // add trailing slash for directories, if present if strings.HasSuffix(tparts[0], "/") && !strings.HasSuffix(t, "/") { t += "/" } - // add trailing slash for directories, if present - if strings.HasSuffix(v, "/") && !strings.HasSuffix(t, "/") { - t += "/" - } - // validate file - if isValidFile(fs, t) { + if validFile(fs, t) { break } } @@ -70,9 +66,9 @@ func To(fs http.FileSystem, r *http.Request, to string, replacer httpserver.Repl return RewriteDone } -// isValidFile checks if file exists on the filesystem. +// validFile checks if file exists on the filesystem. // if file ends with `/`, it is validated as a directory. -func isValidFile(fs http.FileSystem, file string) bool { +func validFile(fs http.FileSystem, file string) bool { if fs == nil { return false }