Remapping Apache to a TC backend, but I would like to filter out unless a certain parameter is set.
ie. http://server/myapp?project=mine
maps to http:server:8080/myapp?project=mine
There will be more parameters (though I will enforce project=mine
as the last).
ProxyPassMatch
works but not for parameters.
I tried
RewriteCond %{QUERY_STRING} project=mine
RewriteRule (.*) localhost:8080
Seems to be close, but testing in CURL I get: This document moved...
Which I do not get with ProxyPass
or ProxyPassMatch
What am I missing ?
Tips/pointers/RTFMs appreciated
You need to use the P
flag on the RewriteRule
to pass the request through mod_proxy, as opposed to being treated as an external 3xx redirect (ie. "this document has moved" msg).
For example, if used directly in the <VirtualHost>
container:
RewriteCond %{QUERY_STRING} (^|&)project=mine$
RewriteRule ^/myapp$ http://server:8080$0 [P]
The condition checks for the URL parameter project=mine
at the end of the query string. Only the URL-path /myapp
is matched (as in your example).
The $0
backreference contains the entire URL-path that is matched by the RewriteRule
pattern. This simply saves repeating /myapp
in the substitution string.
RewriteCond %{QUERY_STRING} project=mine RewriteRule (.*) localhost:8080
There are a few issues with your initial attempt (apart from the missing P
flag):
/anotherapp
would also be caught. But this is also discarded.project=mine
matches that string anywhere in the query string, even as part of other URL params. eg. fooproject=miner
would also match.localhost:8080
is not a valid substitution string.