## 使用方法

reqrep <search> <string> [{if | unless} <cond>]
reqirep <search> <string> [{if | unless} <cond>] (忽略大小写)

<search> is the regular expression applied both to the HTTP headers and to the request. This is an extended regular expression. Grouped parentheses are supported, and the backslash character is not required. All spaces and known separators must be escaped using the backslash “\”. The template is then applied to the entire line.

<string> is the entire line to be added. All spaces and known separators must be escaped using the backslash “\”. You can refer to groups on corresponding patterns by using “\N”, where “N” is an integer between 0 and 9.

<cond> is an optional corresponding condition produced from an ACL. Thus you can ignore this rule when the other conditions are not met.

Any line with a correspondence extended by a regular expression in the “search” argument of a request (in both the request and the header) will be completely replaced by the “string” argument. This is most commonly used to rewrite URLs or domain names in the “host” field of headers, for instance.

### 重点：

“reqrep”关键词严格区分大小写，而“repirep”是大小写不敏感的。

<cond>条件只适用于v3.5.x及以上版本。

## 7层负载均衡配置示例

######## The first public address as seen by the clients
frontend frt
bind 10.0.32.10:80 # address:port to listen to
mode http
log global # use global log parameters
option httplog # Enable HTTP logging
# Replace the “jpg” folder with the “images” folder
reqrep ^([^\ ]*)\ /jpg/(.*) \1\ /images/\2
# Replace any host name in the header with “www.mysite.com”
reqirep ^Host:\ Host:\ www.mysite.com
maxconn 4000 # max conn per instance
timeout client 25s # maximum client idle time (ms)
default_backend bck # send everything to this backend by default

####### This backend manages the servers and the load balancing algorithm
backend bck
balance roundrobin # roundrobin | source | uri | leastconn
mode http
log global # use global log parameters
option httplog # Enable HTTP logging
server srv2 10.0.32.102:80 cookie s2 weight 10 maxconn 100 check inter 1000 fall 3