如何将 URL 的一部分传递给 Apache 中的 ProxyPass

How to pass part of URL to ProxyPass in Apache

我正在点击 URL http://example.com/ws/abc. Now I need to proxy a server with URL https://server.com/abc

我试过以下2种代理方法。但是它不起作用。

  1. RewriteRule ^/ws/(.*) "https://server.com/" [P]
  2. ProxyPassMatch ^/ws/(.*) https://server.com/

可能的问题是什么? 我似乎无法从 URL 中获取 abc。我得到 /ws/abc.

您使用的 RewriteRule 和 ProxyPassMatch 匹配完全相同,因此只有 RewriteRule 被解释,我建议您只使用 proxypass 指令采取更简单的方法。如果我理解正确,你试图代理它会是这样的:

ProxyPass /ws/ https://server.com/
ProxyPass /abc/ https://server.com/

First 将匹配 /ws/ 之后的所有内容并将其附加到 https://server.com/, second will match everything after /abc/ and append it to https://server.com/