I don't have much experience with servers. So, this might be a stupid question.Currently in my Apache server vim /etc/apache2/sites-enabled/000-default.conf file, I have a proxypass as below.
ProxyPass /phpmyadmin !
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
I want to implement a conditional proxy pass for below scenario
if the URL contains ?_escaped_fragment_=
, like the URL below
http://localhost/web/?_escaped_fragment_=/health
I want this URL to be redirected to a URL with a different port like the URL below,
http://localhost:8082/web/?_escaped_fragment_=/health
if the URL doesnt contain ?_escaped_fragment_=
, like the URL below,
http://localhost/web/#!/health
The proxy pass I mentioned earlier which redirects to port 8080 should happen. What is the code for this?
Since ProxyPass can't go inside a If statement you will need to use mod_rewrite to proxy/redirect and use a RewriteCond to filter the query string.
Since query string does not change as it was requested, here is a rough example:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^_escaped_fragment_ [NC]
RewriteRule ^/(.*) http://localhost:8082/$1 [QSA,P,L]
RewriteRule ^/(.*) http://localhost:8080/$1 [P,L]
ProxyPassReverse / http://localhost:8080/
ProxyPassReverse / http://localhost:8082/
Which means, if query_string matches the string "_escaped_fragment_WHATEVERHERE" proxy everything to destination at port 8082 and append whatever query string it was added.
For other cases proxy it will proxy to localhost:8080.
Note that I added QSA which is a flag that says append any query string in original request, but I added it for clarity shake, since mod_rewrite will do it anyways by default in this case. More info about it in the rewrite flags link I add bellow.
You can make this example be much more specific, for example last rewrite will take any other query string, if you don't want that you could filter it out with a more detailed rewritecond earlier or with another rewritecond.
For more details here is what the official docs say about it: Rewrite Flags mod_rewrite