I have 2 applications running on port 8080 and 8085. Both has different URL queries/paths and application on port 8085 have keyword demo on all of its URL queries/paths and other doesn’t. So it acts as an unique identifier
Can I make any change to /etc/httpd/conf/httpd.conf
file so that if the server identifies demo as the keyword then request will reach application on port 8085, if not then request will reach port application on port 8080 ?
If there is a way, please provide sample configuration which goes into httpd.conf file
EDIT 1:
After trying from first 2 of below answers, I couldn’t achieve this. I don’t know if ProxyPass and ProxyPassReverse are not allowing to achieve this. I tried commenting them, adding them in VirtualHost etc. But did not help.
This is the flow we are expecting:
User will hit URL (without mentioning port) like – https://example.com/demo
and this will be routed to app on port 8085
else routed to 8080
May be taking look at my complete httpd.conf might help
Link to my httpd.conf – https://gofile.io/d/tWIHvX
3
Answers
Note: self answer after being able to achieve this
Achieved this using
LocationMatch
directive easily. Below is the configuration.As this is regex dependent you can change to check conditions like ends with, starts with, contains and etc. And both the below LocationMatch conditions are in my httpd.conf
1.If URL
like 192.168.1.113/demo
then go to 80852.If URL
not like 192.168.1.113/demo
then go to 8080Rewrite Condition if the query string contains a word "demo":
Rewrite condition if the query string does not contain the word "demo":
if the SERVER_PORT doesn’t work, please try the port directly like below:
Try:
OR