Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can HAProxy rewrite a URI from "" to "" as it passes a request to the Web server?


share|improve this question
up vote 6 down vote accepted
reqrep  <search> <string>
reqirep <search> <string>   (ignore case)
  Replace a regular expression with a string in an HTTP request line
  May be used in sections :   defaults | frontend | listen | backend
                                 no    |    yes   |   yes  |   yes
  Arguments :
    <search>  is the regular expression applied to HTTP headers and to the
              request line. This is an extended regular expression. Parenthesis
              grouping is supported and no preliminary backslash is required.
              Any space or known delimiter must be escaped using a backslash
              ('\'). The pattern applies to a full line at a time. The "reqrep"
              keyword strictly matches case while "reqirep" ignores case.

    <string>  is the complete line to be added. Any space or known delimiter
              must be escaped using a backslash ('\'). References to matched
              pattern groups are possible using the common \N form, with N
              being a single digit between 0 and 9. Please refer to section
              6 about HTTP header manipulation for more information.

HAProxy 1.3 Documentation

Edit: It is (obviously) up to you whether or not you choose to implement a rewrite using HAProxy, however, I would strongly suggest that you consider using mod_rewrite (or similar) instead.

HAProxy's rewrite functionality is intended to facilitate load-balancing activities and, from a maintenance perspective, webserver behavior should not be coupled to a load-balancer configuration - i.e. if the load-balancer were to be removed from your hosting configuration a single webserver should respond with the same content (and not 404 errors) for a request to a given URI.

share|improve this answer
But if we are using HAProxy rewrites, you don't have to load mod_rewrite on apache (and can disable .htaccess rewrite processing). Both can give some performance boost. Any insights on performance in HAProxy rewrite vs mod_rewrite scenarios? – mixdev Apr 23 '12 at 20:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.