Proxy based on parameter in url

I want to use Apache HTTPd as a proxy:

If the user requests http://xxx?st=yyy , the selected backend server must be server1 . If the user requests http://xxx (there is no st parameter), then the server server must be server2 .

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

+4
source share
1 answer

See http://httpd.apache.org/docs/current/mod/mod_rewrite.html and examples; the fact that:

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

Which then allows you to do things like

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

etc. If this is the whole server - remove / foo / and / before $ 1 - if it is specific to the server - put an additional RewriteCond in front of it to limit the specific host, etc.

+3
source

Source: https://habr.com/ru/post/1388139/


All Articles