canonical += "/"
        }
        if r.URL.Path != canonical {
-               http.Redirect(w, r, canonical, http.StatusMovedPermanently)
+               url := *r.URL
+               url.Path = canonical
+               http.Redirect(w, r, url.String(), http.StatusMovedPermanently)
                redirected = true
        }
        return
                c = c[:len(c)-1]
        }
        if r.URL.Path != c {
-               http.Redirect(w, r, c, http.StatusMovedPermanently)
+               url := *r.URL
+               url.Path = c
+               http.Redirect(w, r, url.String(), http.StatusMovedPermanently)
                redirected = true
        }
        return