如何使用 Apache 反向代理动态 url

发布于 2024-09-03 06:01:44 字数 543 浏览 1 评论 0原文

我希望用户能够在浏览器中加载网址,但不能重定向:

http://example.com/abc/{var1}/{var2}/def

我希望 example.com apache 2.2 服务器接受该请求,并且“隐形”且无需将其重定向到反向代理:

http://other.example.com/abc/{var1}/{var2}/def

我花了几个小时尝试了 RewriteRule、ProxyPass、ProxyPassMatch 和 ProxyPassReverse 的不同组合,但均无济于事。这是我当前的尝试,它似乎重定向到 /test 而不是隐形代理。

RewriteRule ^/abc/([^/\.]+)/([^/\.]+)/def/?$ /test/abc/$1/$2/def [P]
ProxyPass /test http://other.example.com/ 
ProxyPassReverse /test http://other.example.com/

I want a user to be able to load a url in their browser, but not get redirected:

http://example.com/abc/{var1}/{var2}/def

I want the example.com apache 2.2 server to take that request, and "invisibly" and without redirect reverse proxy it to:

http://other.example.com/abc/{var1}/{var2}/def

I have spent hours trying different combinations of RewriteRule, ProxyPass, ProxyPassMatch, and ProxyPassReverse, all to no avail. Here is my current attempt, which seems to do a redirect to /test instead of an invisible proxy.

RewriteRule ^/abc/([^/\.]+)/([^/\.]+)/def/?$ /test/abc/$1/$2/def [P]
ProxyPass /test http://other.example.com/ 
ProxyPassReverse /test http://other.example.com/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

为人所爱 2024-09-10 06:01:44

[P] 标志已经具有 ProxyPass 的功能。您只需要添加一个ProxyPassReverse。另外,如果您想要代理,则必须使用完整的 url 作为 RewriteRule 的第二个操作数。

RewriteRule ^/abc/([^/\.]+)/([^/\.]+)/def/?$ http://other.example.com/abc/$1/$2/def [P]
ProxyPassReverse / http://other.example.com/

The [P] flag already has the functionality of ProxyPass. You only need to add a ProxyPassReverse. Also, if you want to proxy, you must use a full url as the second operand of RewriteRule.

RewriteRule ^/abc/([^/\.]+)/([^/\.]+)/def/?$ http://other.example.com/abc/$1/$2/def [P]
ProxyPassReverse / http://other.example.com/
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文