URL redirect with path
I am trying to create a redirect irule but is not a standard redirect. It basically needs to take the URL + path and redirect it to another website + the path of the old URL. E.g.
www.abc.com/path1/subpath2/ -> https://www.def.com/path1/subpath1/
www.abc.com/path4/subpath5/ -> https://www.def.com/path4/subpath5/
www.abc.com/ - > https://www.def.com/
The Url is not always the same therefore it needs to be flexible. Basically apply everything after the "/" to the new URL.
In a situation where there is no path it just execute a normal redirect. below is my attempt which isn't working, not sure why.
when HTTP_REQUEST {
if { ([string tolower [HTTP::host]] equals "www.abc.com") and ([HTTP::uri] starts_with "/") } {
HTTP::respond 301 Location "https://def.com[HTTP::uri]"
}else {
HTTP::respond 301 Location "https://def.com/"
}
}