diff --git a/README.md b/README.md index 48887a1..d98ecd0 100644 --- a/README.md +++ b/README.md @@ -53,4 +53,20 @@ Fetch methods and What they do - `` acl ismobile req.hdr(User-Agent) -i -m reg (android|iphone) `` Filter the Mobile User-Agents and use a seperate backend for them. reg says contains android or iphone - Filter based on the Host Header : `` acl ischeapshoes req.hdr(Host) -i -m str www.cheapshoes.com ``, `` acl isexpensiveshoes req.hdr(Host) -i -m str www.expensiveshoes.com `` - Match more host on on ACL Rule : `` acl ischeapshoes req.hdr(Host) -i -m str cheapshoes.com www.cheapshoes.com `` -- \ No newline at end of file +- with ``req.hdr()`` can get a header with its name + +## Redirecting +- Use `` redirect prefix `` +- By default, HAProxy uses an HTTP response code 302 +```text +301 The current and all future requests should use the new URL. + +302 The current request should be forwarded to the new URL. Future requests should use the original URL. + +303 The current request should be forwarded to the new URL, but as a GET. For example, if a client sends a POST request to a form that submits a shopping cart, they could be redirected to another page that shows details of the purchase, but using a GET request. This page can be bookmarked, refreshed, etc. without resubmitting the form. This is available in HTTP/1.1. + +307 The current request should be forwarded to the new URL, but do not change the HTTP verb used. For example, if POST was used before, use POST again. Future requests should use the original URL. This is available in HTTP/1.1. + +308 The current and all future requests should use the new URL. Do not change the HTTP verb used. For example, if POST was used before, use POST again. This is available in HTTP/1.1. + +``` \ No newline at end of file diff --git a/haproxy.csw.cfg b/haproxy.csw.cfg index 282619a..f2f2630 100644 --- a/haproxy.csw.cfg +++ b/haproxy.csw.cfg @@ -9,7 +9,6 @@ frontend www-http # Length of URI: acl exactlyfour path_len 4 # Regex: acl isimage path_reg (png|jpg|jpeg|gif)$ # Contains sub-string: acl onsale path_sub -i sale - default_backend apache backend apache diff --git a/haproxy.redirecting.cfg b/haproxy.redirecting.cfg new file mode 100644 index 0000000..cfe4d50 --- /dev/null +++ b/haproxy.redirecting.cfg @@ -0,0 +1,25 @@ +frontend www-http + bind *:81 + mode http + acl apache222 req.hdr(Host) -i -m str apache222.com + redirect prefix http://apache2.com if apache222 + # redirect prefix http://apache2.com code 301 if apache222 + # Specify the code with code number + # redirect prefix http://apache2.com drop-query if apache222 + # drop-query will drop the query params + default_backend apache + +backend apache + description Our Apache Web servers + mode http + balance roundrobin + server web1 127.0.0.1:8081 + server web5 127.0.0.1:8085 + server web6 127.0.0.1:8086 + +backend apache2 + mode http + balance roundrobin + server web1 127.0.0.1:8082 + server web3 127.0.0.1:8083 + server web4 127.0.0.1:8084 \ No newline at end of file