From c689f25b651d28c03176a87fd20c358220a0a9e8 Mon Sep 17 00:00:00 2001 From: XOF Date: Mon, 15 Dec 2025 04:48:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20proxy/rewriter.go?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- proxy/rewriter.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/proxy/rewriter.go b/proxy/rewriter.go index 891f71a..506cdc6 100644 --- a/proxy/rewriter.go +++ b/proxy/rewriter.go @@ -134,10 +134,20 @@ func (r *ContentRewriter) rewriteURL(urlStr string) string { u = r.baseURL.ResolveReference(u) } - // 保留完整的 URL(包括域名) - fullURL := u.String() + // 如果是同域名,只保留路径 + if u.Host == r.baseURL.Host { + proxyPath := u.Path + if u.RawQuery != "" { + proxyPath += "?" + u.RawQuery + } + if u.Fragment != "" { + proxyPath += "#" + u.Fragment + } + return "/p/" + r.token + proxyPath + } - return "/p/" + r.token + "/" + fullURL + // 跨域资源,需要完整 URL + return "/p/" + r.token + "/" + u.String() } func (r *ContentRewriter) rewriteSrcset(srcset string) string {