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 {