Proxy based on parameter in the URL

微笑、不失礼 提交于 2020-01-14 09:10:34

问题


I want to use the Apache HTTPd as a proxy server:

If a user requests http://xxx?st=yyy the chosen backend server should be server1. If a user requests http://xxx (no st parameter) then the backend server should be server2.

I want to know how I need to configure Apache to achieve this.


回答1:


Have a look at http://httpd.apache.org/docs/current/mod/mod_rewrite.html and the examples; specifically you are helped by the fact that:

  • REQUEST_URI The path component of the requested URI, such as "/index.html". This notably excludes the query string which is available as as its own variable named QUERY_STRING.

Which then lets you do things like

RewriteCond  %{QUERY_STRING}  ^$
RewriteRule ^/foo/(.*)$ http://server2/$1 [P,L]

RewriteRule ^/foo/(.*)$ http://server1/$1 [P,L]

and so on. If it is the entire server - remove /foo/ and the / before $1 - if it is server specific - put an extra RewriteCond in front of it to limit to a specific host and so on.



来源:https://stackoverflow.com/questions/8645622/proxy-based-on-parameter-in-the-url

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!