|
@@ -5,6 +5,7 @@ import (
|
|
|
"errors"
|
|
|
"log"
|
|
|
"net/http"
|
|
|
+ "net/url"
|
|
|
"os"
|
|
|
"strings"
|
|
|
|
|
@@ -156,10 +157,24 @@ func (h *ProxyHandler) handleRootRouting(w http.ResponseWriter, r *http.Request)
|
|
|
}
|
|
|
return
|
|
|
} else {
|
|
|
- //Redirect to target
|
|
|
- h.logRequest(r, false, 307, "root-redirect", domainOnly)
|
|
|
- http.Redirect(w, r, h.Parent.RootRoutingOptions.UnsetRuleRedirectTarget, http.StatusTemporaryRedirect)
|
|
|
- return
|
|
|
+ //Validate the redirection target URL
|
|
|
+ parsedURL, err := url.Parse(h.Parent.RootRoutingOptions.UnsetRuleRedirectTarget)
|
|
|
+ if err != nil {
|
|
|
+ //Error when parsing target. Send to root
|
|
|
+ h.proxyRequest(w, r, h.Parent.Root)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ hostname := parsedURL.Hostname()
|
|
|
+ if domainOnly != hostname {
|
|
|
+ //Redirect to target
|
|
|
+ h.logRequest(r, false, 307, "root-redirect", domainOnly)
|
|
|
+ http.Redirect(w, r, h.Parent.RootRoutingOptions.UnsetRuleRedirectTarget, http.StatusTemporaryRedirect)
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ //Loopback request due to bad settings (Shd leave it empty)
|
|
|
+ //Forward it to root proxy
|
|
|
+ h.proxyRequest(w, r, h.Parent.Root)
|
|
|
+ }
|
|
|
}
|
|
|
} else {
|
|
|
//Route to root
|