Skip to content

Commit

Permalink
Redirecting written
Browse files Browse the repository at this point in the history
  • Loading branch information
Gharib110 committed Mar 6, 2024
1 parent f64d0d8 commit a38f67e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ``
-
- with ``req.hdr(<Header_Name>)`` 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.
```
1 change: 0 additions & 1 deletion haproxy.csw.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions haproxy.redirecting.cfg
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a38f67e

Please sign in to comment.