Mass redirect using Haproxy map file

During application upgrades or migrations it’s common to keep old URLs working for backward compatibility. One simple way to handle large numbers of redirects in HAProxy is to use a map file. If you are using Nginx, you can find a similar approach here: Nginx.

This method keeps the main HAProxy configuration clean and makes it easy to manage many redirects in a separate file.

Haproxy config example

 frontend http
  bind *:80
  bind *:443 ssl crt /etc/haproxy/all-domain-com.pem
...
  http-request redirect location %[capture.req.uri,map(/etc/haproxy/redirect.map)] code 301 if { capture.req.uri,map(/etc/haproxy/redirect.map) -m found and hdr(host) -i domain.com }
...
  redirect scheme https code 301 if !{ ssl_fc }

Redirect MAP

# cat /etc/haproxy/redirect.map | head -5
/free-slot-online    https://domain.com/all-games
/free-auto-spin-slot    https://domain.com/auto-spin
/free-auto-play-slot    https://domain.com/auto-play
/free-wild-slot-online    https://domain.com/wild-symbols
/5-reel-slot-online    https://domain.com/5-reels
Human Logic, AI Syntax... Note on Content: I'm a Systems Engineer, not a native English writer. To ensure my technical ideas are clear and accessible, I use AI tools to polish the grammar and style. The workflow is simple: I provide the logic, the code, and the real-world experience. The AI handles the "English-to-Human" translation layer. If you find a bug, that's on me. If you find a perfectly placed comma, that's probably the AI.

Comments

Popular posts from this blog

FreeRadius with Google Workspace LDAP

Fixing pssh (parallel-ssh) Problems on Debian 10 with Python 3.7