如何使用 Apache 反向代理动态 url
我希望用户能够在浏览器中加载网址,但不能重定向:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
[P] 标志已经具有 ProxyPass 的功能。您只需要添加一个
ProxyPassReverse
。另外,如果您想要代理,则必须使用完整的 url 作为RewriteRule
的第二个操作数。The [P] flag already has the functionality of
ProxyPass
. You only need to add aProxyPassReverse
. Also, if you want to proxy, you must use a full url as the second operand ofRewriteRule
.