I put my example in here: https://dooby.fr/links/?IxO7cg
http-request redirect code 301 location https://my.url.com%[path,regsub(^/my_old_path,,)] if { path_beg /my_old_path }
here, the purpose is to redirect a hit on https://url.com/my_old_path/foo/bar/baz
to https://my.url.com/foo/bar/baz
PaulL
December 21, 2021, 9:18pm
2
Thank you! I’ve been looking for a solution on how to alter the path on a redirect.
I adapted your solution to preserve the query parms by changing “path” to “capture.req.uri” as follows:
http-request redirect code 301 location https://my.url.com %[capture.req.uri,regsub(^/my_old_path,)] if { path_beg /my_old_path }
This allows me to rewrite
https://my.url.com/my_old_path/foo/bar/baz?p1=v1&p2=v2&p3=v3
to
https://my.url.com/foo/bar/baz?p1=v1&p2=v2&p3=v3