# How to redirect changing path in the backend

**URL:** <https://discourse.haproxy.org/t/how-to-redirect-changing-path-in-the-backend/5445>\
**Category:** Help!\
**Created:** [July 8, 2020, 12:38am UTC](https://discourse.haproxy.org/t/how-to-redirect-changing-path-in-the-backend/5445 "2020-07-08T00:38:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ethraza](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.haproxy.org/ethraza/32/1214_2.png) [@ethraza](https://discourse.haproxy.org/u/ethraza)\
**Post date:** [July 8, 2020, 12:38am UTC](https://discourse.haproxy.org/t/how-to-redirect-changing-path-in-the-backend/5445/1 "2020-07-08T00:38:37Z")

</div>

I have Portainer running at **[portainer\_agent:9000](http://portainer_agent:9000)** in my Swarm. I would like to access **[http://myserver.com/portainer](http://myserver.com/portainer)** to get portainer, but I can’t find how to accomplish that.  
The “http-request set-path” I’m using at backend is almost working, but it’s not quite there yet.  
So the question: How to get the path **/portainer/anything** redirected to **/anything** at the backend.

Here is my haproxy.conf snippet:

```
frontend http-in
    bind *:80
    
    acl is_portainer path_beg /portainer
    use_backend portainer if is_portainer

backend portainer
    balance leastconn
    mode http
    http-request set-path "%[path,regsub(^/portainer,/,)]" if { path_beg /portainer }
    server portainer portainer_agent:9000 resolvers docker_resolver resolve-prefer ipv4

```

Thank you.

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [July 8, 2020, 6:56am UTC](https://discourse.haproxy.org/t/how-to-redirect-changing-path-in-the-backend/5445/2 "2020-07-08T06:56:43Z")

</div>

You don’t, because all the links in the payload would have to be rewritten as well, redirects from the backend, cookies, etc. This is a never-ending story and haproxy cannot rewrite some of it.

Instead, use a dedicated Hostname, so you don’t have to deal with path, cookie, payload rewriting, etc.
