Skip to content

Instantly share code, notes, and snippets.

@ldesiqueira
Forked from meineerde/haproxy.cnf
Created January 25, 2018 00:00
Show Gist options
  • Save ldesiqueira/60b37ab08a0bd012d6e5e181ae2d3493 to your computer and use it in GitHub Desktop.
Save ldesiqueira/60b37ab08a0bd012d6e5e181ae2d3493 to your computer and use it in GitHub Desktop.
Redirect *.example.com to *.example.org with HAProxy
# We use a temporary header to build our new Host header from the existing one
# and then directly perform a redirect
# Clean the request and remove any existing header named X-Rewrite
http-request del-header X-REWRITE
# Copy the Host header into X-Rewrite unchanged
http-request add-header X-REWRITE %[hdr(host)] if { hdr_end(host) .example.com }
# Change the X-REWRITE Header to contain out new host name
http-request replace-header X-REWRITE (.*)\.example\.com$ \1.example.org if { hdr_count(X-REWRITE) gt 0 }
# Perform the 301 redirect
http-request redirect code 301 location %[hdr(X-REWRITE)]%[req.uri] if { hdr_count(X-REWRITE) gt 0 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment