Redirect best practice with same URI

When doing a frontend redirect where the path and parms (aka URI) remain the same, is there a best practice to use redirect prefix vs redirect location?

Example - Redirect prefix vs redirect location both give same results:

http-request redirect code 302 prefix https://my.url.com if { path_beg /my_path } #redirect prefix does not alter the path or parms (aka URI)
http-request redirect code 302 location https://my.url.com%[capture.req.uri] if { path_beg /my_path } #passes the un-altered path and parms (aka URI) w/redirect location

Absolutely use redirect prefix, because it specifically addresses this use-case.

If you build your own redirect string by accessing variables like %[capture.req.uri] as opposed to using the haproxy internal features that do this job for you, you need to take care of all the specifics.

For example: Afaik uri could contain an absolute path, especially in HTTP/2, so this would break the redirect.

1 Like

Thank you!