如何使用 ProxyPass 发送不编码的查询参数?

How to use ProxyPass to send a query parameter without encoding it?

在我的 apache 配置中,我正在匹配一些 url 并试图将其重定向到另一个位置。在大多数情况下,此配置是有效的。不是的部分是代理传递 url 上的查询参数。我所有的研究都在引导我使用 RewriteRule,但这对我来说毫无意义,因为我完全丢弃了传入的 url,因为在它用于匹配 Location 块后并不重要。

<Location "/src">
     ProxyErrorOverride Off
     ProxyPass https://example.com/dst/v1234?user=me
     ProxyPassReverse https://example.com/dst/v1234?user=me
     Header set Cache-Control "max-age=604800, public"
</Location

当我测试时,我可以看到以下内容:

应用服务器不知道如何解释 %3f,即使那是问号 (?) 的 url 编码。 App Server 不在我的控制之下,我无法更改该代码来为我解码。如何让 Apache 发送问号 (?) 而不是 url 编码变体?

经过大量研究和另一个非常有用的 Stack Overflow post。我找到了解决方案!

ProxyPass /webservice balancer://api/webservice nocanon

Apache mod_proxy url encoding

答案是使用nocanon.

<Location "/src">
     ProxyErrorOverride Off
     ProxyPass https://example.com/dst/v1234?user=me nocanon
     ProxyPassReverse https://example.com/dst/v1234?user=me
     Header set Cache-Control "max-age=604800, public"
</Location

Normally, mod_proxy will canonicalise ProxyPassed URLs. But this may be incompatible with some backends, particularly those that make use of PATH_INFO. The optional nocanon keyword suppresses this and passes the URL path "raw" to the backend. Note that this keyword may affect the security of your backend, as it removes the normal limited protection against URL-based attacks provided by the proxy.

https://httpd.apache.org/docs/2.4/mod/mod_proxy.html