From fabef83a4cd2755df741355c8fa11a80dee5696a Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Wed, 7 Apr 2021 11:20:44 +0800 Subject: [PATCH] =?UTF-8?q?URL=E8=B7=B3=E8=BD=AC=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=E5=89=8D=E7=BC=80=E5=92=8C=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E4=BF=9D=E7=95=99RequestURI=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/http_request_host_redirect.go | 32 +++++++++++++++----- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/internal/nodes/http_request_host_redirect.go b/internal/nodes/http_request_host_redirect.go index 1abda16..a13ba69 100644 --- a/internal/nodes/http_request_host_redirect.go +++ b/internal/nodes/http_request_host_redirect.go @@ -1,6 +1,9 @@ package nodes -import "net/http" +import ( + "net/http" + "strings" +) // 主机地址快速跳转 func (this *HTTPRequest) doHostRedirect() (blocked bool) { @@ -9,13 +12,28 @@ func (this *HTTPRequest) doHostRedirect() (blocked bool) { if !u.IsOn { continue } - if fullURL == u.RealBeforeURL() { - if u.Status <= 0 { - http.Redirect(this.RawWriter, this.RawReq, u.AfterURL, http.StatusTemporaryRedirect) - } else { - http.Redirect(this.RawWriter, this.RawReq, u.AfterURL, u.Status) + if u.MatchPrefix { + if strings.HasPrefix(fullURL, u.BeforeURL) { + afterURL := u.AfterURL + if u.KeepRequestURI { + afterURL += this.RawReq.URL.RequestURI() + } + if u.Status <= 0 { + http.Redirect(this.RawWriter, this.RawReq, afterURL, http.StatusTemporaryRedirect) + } else { + http.Redirect(this.RawWriter, this.RawReq, afterURL, u.Status) + } + return true + } + } else { + if fullURL == u.RealBeforeURL() { + if u.Status <= 0 { + http.Redirect(this.RawWriter, this.RawReq, u.AfterURL, http.StatusTemporaryRedirect) + } else { + http.Redirect(this.RawWriter, this.RawReq, u.AfterURL, u.Status) + } + return true } - return true } } return