Acl giving "404 Not Found"

I am a newb to HAProxy, and am bashing my head against this one. I’m trying to set up what I think is a fairly simple exercise in redirecting a url to a specific port. I’d like for http://server.example.com/application to redirect to http://server.example.com:8091. To that end, I have the following config:

global
    daemon
    maxconn 256

defaults
    mode http
    timeout connect 50000ms
    timeout client 50000ms
    timeout server 50000ms

frontend http-in
    bind *:80
    acl application url_end application
    use_backend application_admin if application
    default_backend web

backend application_admin
    server server1 127.0.0.1:8091

backend web
    server server1 127.0.0.1:8080

The redirect to 8080 as the default works fine, apache is listening on 8080. But when I go to server.example.com/application, I get a 404 error:

curl -v server.example.com/application
*   Trying server.example.com...
* TCP_NODELAY set
* Connected to server.example.com (server.example.com) port 80 (#0)
> GET /application HTTP/1.1
> Host: server.example.com
> User-Agent: curl/7.51.0
> Accept: */*
>
< HTTP/1.1 404 Object Not Found
< Server: MochiWeb/1.0 (Any of you quaids got a smint?)
< Date: Wed, 08 Feb 2017 23:00:51 GMT
< Content-Type: text/plain
< Content-Length: 10
< Cache-Control: max-age=10
<
* Curl_http_done: called premature == 0
* Connection #0 to host server.example.com left intact
Not found.

The port does work, because I can browse directly to server.example.com:8091.

Any help greatly appreciated!

Well, I’ve made some progress. I added the following:

reqrep ^([^\ ]*\ )/couchbase(.*) \1\ /\2

To my backend application_admin above. It is now sort of attempting to do the right thing, but it’s dropping the port in the final url:

curl -v server.example.com/application
* About to connect() to server.example.com port 80 (#0)
*   Trying server.example.com...
* Connected to server.example.com (server.example.com) port 80 (#0)
> GET /application HTTP/1.1
> User-Agent: curl/7.29.0
> Host: server.example.com
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Server: Application Server
< Pragma: no-cache
< Location: http://server.example.com/ui/index.html
< Date: Thu, 09 Feb 2017 17:22:11 GMT
< Content-Type: text/html
< Content-Length: 234
< Cache-Control: no-cache
<
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><html><head><title>301 Moved Permanently</title></head><body><h1>Moved Permanently</h1><p>The document has moved <a href="http://server.example.com/ui/index.html>here</a>.</p></body></html>
* Connection #0 to host server.example.com left intact

The final url should actually be http://server.example.com:8091/ui/index.html like so:

curl -v server.example.com:8091
* About to connect() to server.example.com port 8091 (#0)
*   Trying server.example.com...
* Connected to server.example.com (server.example.com) port 8091 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: server.example.com:8091
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Server: Application Server
< Pragma: no-cache
< Location: http://server.example.com:8091/ui/index.html
< Date: Thu, 09 Feb 2017 17:27:04 GMT
< Content-Type: text/html
< Content-Length: 239
< Cache-Control: no-cache
<
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><html><head><title>301 Moved Permanently</title></head><body><h1>Moved Permanently</h1><p>The document has moved <a href="http://server.example.com:8091/ui/index.html>here</a>.</p></body></html>
* Connection #0 to host server.example.com left intact

Clearly I’m not understanding the regex well enough, but I’m not sure where I’m going wrong.

I ended up going a different direction with this. Instead of using server I used http-request redirect instead. Works a treat!