Apache mod_rewrite/mod_proxy - 将 URI 的最后部分重写为查询字符串?
我们有一个可以通过以下形式的 URL/URL 访问的 Web 资源:
http://[host1]:[port1]/aaa/bbb.ccc?param1=xxx¶m2=yyy...< /code>
但是,我们正在使用外部(即不是由我们开发,因此不在我们的控制之下,即我们无法更改它)客户端应用程序,该应用程序尝试使用如下 URL 访问我们的资源:
http://[host2]/[port2]/ddd/fff/param1=xxx¶m2=yyy...
换句话说,客户端包含“查询字符串”(?param1=xxx¶m2=yyy...
部分) 就好像它是 URI 的一部分,而不是作为正确的查询字符串。
我们有一个单独的 Apache 代理实例,我们认为可以将其与某些 RewriteCond/RewriteRule 一起使用来获取传入请求(在“URI”末尾带有查询字符串且没有“?”的请求)。 )并使用“正确的”查询字符串将 URI 重写为“正确的”URI,然后使用修改/重写的 URI 通过代理访问我们的资源。
我们还希望在没有 HTTP 重定向(例如 30x)返回到客户端的情况下做到这一点,因为看起来他们可能无法处理这样的重定向。
我一直在尝试各种事情,但我对 Apache mod_rewrite 不太熟悉,所以我想知道是否有人可以告诉我(1)这是否可能,以及(2)建议 RewriteCond/RewriteRule 可以实现什么?
PS我已经取得了一些进展。下面正确地重写了 URL,但是当我测试时,我看到 302 重定向到重写的 URL,而不是 Apache 立即代理到重写的 URL。是否可以在不重定向(302)的情况下做到这一点?
<Location /test/users/>
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/(.*)/param1=
RewriteRule ^/(.*)/param1=(.*) http://192.168.0.xxx:yyyy/aaa/bbbbb.ccc?base=param1=$2
</Location>
谢谢,吉姆
We have a web resource that can be accessed with a URL/URL of the form:
http://[host1]:[port1]/aaa/bbb.ccc?param1=xxx¶m2=yyy...
However, we are working with an external (i.e., not developed by us, so not under our control, i.e., we can't change it) client app that is attempting to access our resource with a URL that looks like:
http://[host2]/[port2]/ddd/fff/param1=xxx¶m2=yyy...
In other words, the client is including the "query string" (the ?param1=xxx¶m2=yyy...
part) as if it's part of the URI, instead of as a proper query string.
We have a separate Apache proxy instance, and we're thinking that we could use that with some RewriteCond/RewriteRule to take the incoming requests (the ones with the query string at the end of the "URI", and without the "?") and rewrite the URI to a "proper" URI with a "proper" query string and then use that modified/re-written URI to access our resource via proxy.
We'd also like to do that without having an HTTP re-direct (e.g., 30x) going back to the client, because it appears that they may not be able to handle such a re-direct.
I've been trying various things, but I'm not that familiar with Apache mod_rewrite, so I was wondering if someone could tell me (1) if this is possible and (2) suggest what RewriteCond/RewriteRule would accomplish this?
P.S. I have gotten some progress. The following re-writes the URL correctly, but when I test, I'm seeing a 302 redirect to the re-written URL, instead of Apache just proxying immediately to the re-written URL. Is it possible to do this without the re-direct (302)?
<Location /test/users/>
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/(.*)/param1=
RewriteRule ^/(.*)/param1=(.*) http://192.168.0.xxx:yyyy/aaa/bbbbb.ccc?base=param1=$2
</Location>
Thanks, Jim
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论