# How to create properly rewrite in HAproxy

**URL:** <https://discourse.haproxy.org/t/how-to-create-properly-rewrite-in-haproxy/156>\
**Category:** Help!\
**Created:** [March 8, 2016, 4:25pm UTC](https://discourse.haproxy.org/t/how-to-create-properly-rewrite-in-haproxy/156 "2016-03-08T16:25:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@Michael](https://discourse.haproxy.org/u/Michael)\
**Post date:** [March 8, 2016, 4:25pm UTC](https://discourse.haproxy.org/t/how-to-create-properly-rewrite-in-haproxy/156/1 "2016-03-08T16:25:35Z")

</div>

Hello,

I’m new in HAProxy can you tell my how I can properly configuring rewrite in HAproxy?

* * *

frontend main  
bind \*:80  
acl simple hdr\_end(host) -i [simpledomain.com](http://simpledomain.com)  
use\_backend app if simple  
mode http

## backend app mode http server srv1 192.168.10.3:8080 reqrep ^([^\ :]_)\ /(._) \1\ /simpleapp/\2 |\<-- this line isn’t work

I have this config and I want to do this forwarding:

[simpledomain.com](http://simpledomain.com) —\> 192.168.10.3:8080/simpleapp  
(where address [simpledomain.com](http://simpledomain.com) = 192.168.10.5:80.)

The forwarding work only that, without rewrite /simpleapp:  
[simpledomain.com](http://simpledomain.com) —\> 192.168.10.3:8080

What should be changed in this configuration to make it work?

Regards,  
Michael

---

<div class="post-metadata">

**Author:** ![ahayworth](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.haproxy.org/ahayworth/32/11_2.png) [@ahayworth](https://discourse.haproxy.org/u/ahayworth)\
**Post date:** [March 21, 2016, 9:12pm UTC](https://discourse.haproxy.org/t/how-to-create-properly-rewrite-in-haproxy/156/2 "2016-03-21T21:12:35Z")

</div>

Hi Michael -

You could do something like the following:

```auto
backend app
  mode http
  server srv1 192.168.10.3:8080
  http-request set-path /simpleapp%[path,regsub(/,)]

```

We do something similar at my company.

Hope that helps!

- Andrew

---

<div class="post-metadata">

**Author:** ![Michael](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@Michael](https://discourse.haproxy.org/u/Michael)\
**Post date:** [March 24, 2016, 3:36pm UTC](https://discourse.haproxy.org/t/how-to-create-properly-rewrite-in-haproxy/156/3 "2016-03-24T15:36:55Z")

</div>

Hello,

## Thank you for respons. Now I have this configuration:

frontend main  
bind \*:80  
acl simple hdr\_end(host) -i [simpledomain.com](http://simpledomain.com)  
use\_backend app if simple  
mode http

## backend app mode http server srv1 192.168.10.3:8080 http-request set-path /simpleapp%[path,regsub(/,)]

But I have this error when I start haproxy:

[root@localhost ~]# service haproxy restart  
[ALERT] 083/163150 (2599) : parsing [/etc/haproxy/haproxy.cfg:131]: ‘http-request’ expects ‘allow’, ‘deny’, ‘auth’, ‘redirect’, ‘tarpit’, ‘add-header’, ‘set-header’, ‘replace-header’, ‘replace-value’, ‘set-nice’, ‘set-tos’, ‘set-mark’, ‘set-log-level’, ‘add-acl’, ‘del-acl’, ‘del-map’, ‘set-map’, but got ‘set-path’.  
[ALERT] 083/163150 (2599) : Error(s) found in configuration file : /etc/haproxy/haproxy.cfg  
Errors in configuration file, check with haproxy check

The line 131 in haproxy.cfg is:  
" http-request set-path /simpleapp%[path,regsub(/,)]"

I have version 1.5.4 and in this v. ‘set-path’ doesn’t work. It’s work in v.1.7

Regards,  
Michael
