首页 文章

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

提问于
浏览
2

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

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/

1 回答

  • 0

    [P]标志已具有 ProxyPass 的功能 . 您只需要添加 ProxyPassReverse . 此外,如果要进行代理,则必须使用完整URL作为 RewriteRule 的第二个操作数 .

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

相关问题