diff --git a/caddy/setup/rewrite.go b/caddy/setup/rewrite.go index e642d071f..4c84cb5fd 100644 --- a/caddy/setup/rewrite.go +++ b/caddy/setup/rewrite.go @@ -2,6 +2,7 @@ package setup import ( "net/http" + "strings" "github.com/mholt/caddy/middleware" "github.com/mholt/caddy/middleware/rewrite" @@ -54,10 +55,11 @@ func rewriteParse(c *Controller) ([]rewrite.Rule, error) { } pattern = c.Val() case "to": - if !c.NextArg() { + args1 := c.RemainingArgs() + if len(args1) == 0 { return nil, c.ArgErr() } - to = c.Val() + to = strings.Join(args1, " ") case "ext": args1 := c.RemainingArgs() if len(args1) == 0 { diff --git a/middleware/rewrite/condition.go b/middleware/rewrite/condition.go index ab69ef4af..51d4b3a26 100644 --- a/middleware/rewrite/condition.go +++ b/middleware/rewrite/condition.go @@ -2,10 +2,11 @@ package rewrite import ( "fmt" - "github.com/mholt/caddy/middleware" "net/http" "regexp" "strings" + + "github.com/mholt/caddy/middleware" ) const ( @@ -19,7 +20,7 @@ const ( ) func operatorError(operator string) error { - return fmt.Errorf("Invalid operator", operator) + return fmt.Errorf("Invalid operator %v", operator) } func newReplacer(r *http.Request) middleware.Replacer { diff --git a/middleware/rewrite/to.go b/middleware/rewrite/to.go index 294b8f045..1dc48fdbd 100644 --- a/middleware/rewrite/to.go +++ b/middleware/rewrite/to.go @@ -54,6 +54,10 @@ func To(fs http.FileSystem, r *http.Request, to string) bool { // isValidFile 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 { + if fs == nil { + return false + } + f, err := fs.Open(file) if err != nil { return false