-
-
Save sinfere/afd8a16647b4ba07f65f55d5472dd365 to your computer and use it in GitHub Desktop.
HAProxy Redirecting based on an HTTP Query or a Map with a fallback redirect based on host header
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This file contains only partial paths to match on | |
# This file should reside in the same directory as the haproxy.cfg simply due to the way it is configured in the sample snippet-but they can go anywhere in the /etc/haproxy directory | |
/my-partial- https://subdomain3.mydomain.com/my-new-full-path |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ACL for matching on a hostname | |
acl target_host hdr(host) -i subdomain2.mydomain.com | |
# ACL for matching on a query parameter (e.g. ?foo=bar) | |
acl my_query_param query queryname=value | |
# Match on partial path in the map that includes the query | |
http-request redirect location %[path,map_beg(beg_redirect.map)]?%[query] code 301 if { path,map_beg(beg_redirect.map) -m found } my_query_param target_host | |
# Match on partial path | |
http-request redirect location %[path,map_beg(beg_redirect.map)] code 301 if { path,map_beg(beg_redirect.map) -m found } target_host | |
# Match on full path that includes the query | |
http-request redirect location %[capture.req.uri,map(redirect.map)]?%[query] code 301 if { capture.req.uri,map(redirect.map) -m found } my_query_param target_host | |
# Match on full path | |
http-request redirect location %[capture.req.uri,map(redirect.map)] code 301 if { capture.req.uri,map(redirect.map) -m found } target_host | |
# General catch all if none of the previous rules have matched | |
http-request redirect location https://subdomain3.mydomain.com code 301 if target_host |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This file contains full paths to redirect | |
# This file should reside in the same directory as the haproxy.cfg simply due to the way it is configured in the sample snippet-but they can go anywhere in the /etc/haproxy directory | |
/my-old-path https://subdomain3.mydomain.com/my-new-path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment