Pergunta

I think the subject covers it. I need to build a list of many 301 redirects within the same domain i.e. redirect /some_old_place to /some_new_place. We have lots of content the gets retired or replaced based on uri. The quote from the current home page of haproxy states maps may be used to "build massive redirect tables" but for the life of me I can figure it out. I am using version 1.5 and here are the lines of the config which I am currently am working on.

    redirect location %[map(/opt/local/etc/haproxy/redirect.map), hdr(url)] code 301

Given the above config line I get

[ALERT] 099/205518 (27981) : parsing [/opt/local/etc/haproxy/haproxy.cfg:83] : error detected in frontend 'LoadBalancer' while parsing redirect rule : expects 'code', 'prefix', 'location', 'scheme', 'set-cookie', 'clear-cookie', 'drop-query' or 'append-slash' (was 'hdr(url)]').

I have tried many variations of this but have not found any success. If anyone knows how to do this please let me know?

Foi útil?

Solução

This was the solution I came up with. Thanks JStarcher for the tip about spaces.

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 } 

In the referenced file redirect.map I have a source uri on the left and a destination separated by a space on the right.

/some_old_page.html /some_new_page.html

I have over 2k lines in the file at this point and I have seen no noticeable slowdown.

Outras dicas

You have to use the http-request redirect directive which supports log-format strings.

Another little tricky gotcha, you can't have a space after the comma.

Try this:

http-request redirect location %[hdr(host),map(/opt/local/etc/haproxy/redirect.map)] code 301
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top