08-Feb-2022 07:38
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/"
}
}
08-Feb-2022 10:30
A couple comments/questions...
That said, assuming you don't need any redirects for the non-matching host, here's how I'd write that:
when HTTP_REQUEST {
if { ([HTTP::host] eq "www.abc.com") and not([HTTP::uri] eq "/") } {
HTTP::respond 301 Location "http://jrahmtest.local[HTTP::uri]"
event disable all
} elseif { [HTTP::host] eq "www.abc.com" } {
HTTP::respond 301 Location "http://jrahmtest.local/"
event disable all
}
}
Test results:
08-Feb-2022 11:02
jRahm thank you for your reply/suggestion. Unfortunately, it didn't work properly.
www.abc.com redirect to www.def.com work fine
However,
www.abc.com/somepath/someotherpath/ redirect to www.def.com/somepath/someotherpath/ did not work. It just redirects without the path.
08-Feb-2022 11:56
do you have a dump capturing what the BIG-IP is returning? you could also capture the redirect in HTTP_RESPONSE_RELEASE I think. Its working on my end, not sure what the issue is, will need to see what you're seeing.
11-Feb-2022 00:14
We were unable to get the iRule to work, therefore we sent the traffic to an apache server and on the server, we were able to configure the redirect to the right path. Thank you for your help.
11-Feb-2022 05:48
Glad you found a solution! If you want to keep working it happy to help, this is totally doable with an iRule, we must be missing a piece of logic.