Apache mod_rewrite/mod_proxy - 将 URI 的最后部分重写为查询字符串?

发布于 2024-11-17 16:55:48 字数 1133 浏览 4 评论 0原文

我们有一个可以通过以下形式的 URL/URL 访问的 Web 资源:

http://[host1]:[port1]/aaa/bbb.ccc?param1=xxx&param2=yyy...< /code>

但是,我们正在使用外部(即不是由我们开发,因此不在我们的控制之下,即我们无法更改它)客户端应用程序,该应用程序尝试使用如下 URL 访问我们的资源:

http://[host2]/[port2]/ddd/fff/param1=xxx&param2=yyy...

换句话说,客户端包含“查询字符串”(?param1=xxx&param2=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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文