I have a backend trying to route traffic to a specific IP address and a port. The first hit on the url doesn't contain the port number. But the subsequesnt requests from within the website is not redirected properly.
Example: http://test.com has server 123.45.67.89:9080
When I try the URL http://test.com/login --> It is redirected correctly and I get the login page.
But once I give the login details and press OK. It is redirected to http://test.com:9080/loginSuccess.
The page is available under http://test.com/loginsuccess
This is the backend code and all the ways I have tried from different solution is commented.
backend lf_was_9080
acl auth_lf_was http_auth(lf_was_auth_list)
http-request auth realm lf_was_auth_list if !auth_lf_was
mode http
#TRY 1
#http-request redirect prefix http://test.com/login if { hdr(host) -i test.com:9080/login }
#TRY 2
# Clean the request and remove any existing header named X-Rewrite
http-request del-header X-REWRITE
# Copy the full request URL into X-Rewrite unchanged
http-request add-header X-REWRITE %[url] if { path_sub 9080/login }
# Change the X-REWRITE header to contain out new path
http-request replace-header X-REWRITE ^:9080/login(/.*)?$ /login\1 if { hdr_cnt(X-REWRITE) gt 0 }
# Perform the 301 redirect
http-request redirect code 301 location http://%[hdr(host)]%[hdr(X-REWRITE)] if { hdr_cnt(X-REWRITE) gt 0 }
#TRY 3
#reqrep ^([^\ :]*)\ /login/(.*) \1\ /login/\2
#TRY 4
#http-request redirect prefix https://test.com if { hdr(host) -i test.com:9080 }
server lf_was_9080 10.85.200.158:9080 check
I have also https redirect which works perfectly.
How can i rewrite the url without the port number in Haproxy?