How to effectively manage long redirect lists

We are migrating a range of webservers into a new farm which will have HaProxy at the front door to route all the traffic inside the farm properly. We already know how to do that as it is similar to 6 other farms that we built that way.

This time we’ll get a huge list of redirects that these guys managed in Apache config files so far. We would like to handle all redirects across hundreds of domains as early as possible and therefore look into best ways to handle them.

We know how tpo do that with ACLs in the haproxy.cfg file for each redirect inndividually. Now, that may end up in a huge file which may not be the most efficient way of doing this. Are there better way of doing this, e.g. some sort of lookup table in e.g. YAML or JSON format?

Or any other suggestions?

You’d use a map file for that, where you can insert tens of thousands of redirects without slowing haproxy down.

See:
http://cbonte.github.io/haproxy-dconv/1.7/configuration.html#7.1

1 Like

Great, this is exactly what I was looking for. Have you got any experience about a bigger number of mapping files too? I’m wondering because I would probably have a mapping file for each domain, as they all have different mappings. Ideally I would probably want to use the domain name as a variable mapping file name. Do you think that’s possible too?

A high number of mapping tables should not be a problem, but I’m not sure about variable mapping file names, because the map files are only read at initialization. Can you elaborate how your configuration looks like today and how you’d use those variable file names?

Here is a sample of a redirect which only applies to one domain of many that are handled by the same frontend:

http-request redirect code 301 location https://www.example.com/en-ac if { hdr(host) -i -n example.com } { path_reg ^/en }

So, a request to http://example.com/en should be redirected to https://www.example.com/en-ac

I guess I could still add the header host condition when using the map feature, so that doesn’t require variable mapping file names now that I’m looking at it.

I see what you mean. Yes, we can do this, its even an example in the documentation:

http-request redirect code 301 \
location http://www.%[hdr(host)]%[capture.req.uri] \
unless { hdr_beg(host) -i www }
1 Like

Perfect, thanks a lot @lukastribus for your help on this.

BTW, it’s not only the redirect from example.com to www.example.com, it’s also from http to https and from /en to /en-ac in the example I provided above. But all that should be possible with maps too.