12-Apr-2021 01:11
Hello experts 🙂
I'm really new to BIG IP and need to make some irules for some hosts. My Problem is that i need some "special" redirects and the one i searched and tested did not work for me.
What do i need:
If a User goes to https://example.com it should be redirect to https://example.com/content
If a User goes to https://example.com/pwreset it should be redirect to https://example2.com/xxx
If a user goes to https://example.com/admin it should be redirect to https://example.com/#/login
when HTTP_REQUEST {
if { [HTTP::path] eq "/" } {
HTTP::redirect "https://example.com/content"
}
if { [HTTP::path] eq "/admin" } {
HTTP::redirect " https://example.com/#/login"
}
elseif { [HTTP::uri] eq "/pwreset"} { HTTP::redirect "https://example2.com/xxx"
}
}
But it looks like that if i go to /admin bigIP redirects to https://example.com/#/login but because of the /#/ the first line maches as well. Sorry if it is a dump question but im not really good at writing code and so.
Later i have to check also if teh request for /admin is coming from aninternal or external IP, but thats something i will try after the redirect itself are working.
Would be really great if someone could point me in the right direction or help me out 🙂
best regards
Bela
12-Apr-2021
02:42
- last edited on
04-Jun-2023
20:58
by
JimmyPackets
Try below
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::uri]] {
"/" {
HTTP::respond 301 Location "https://example.com/content"
}
"/admin*" {
if { [class match [IP::client_addr] equals "datagroup_internal"] } {
HTTP::respond 301 Location "https://example.com/#/login"
} else {
reject
}
}
"/pwreset*" {
HTTP::respond 301 Location "https://example2.com/xxx"
} default {
return
}
}
}
12-Apr-2021 07:56
Nice example.
12-Apr-2021 02:58
Strange maybe the f5 thinks that /# is a query and not part of the path atribute and this is why https://example.com/#/login matches the first rule as the F5 irule path option thinks that https://example.com/#/login is https://example.com/.
Try using F5 URI HTTP::uri and maybe do somethink like:
when HTTP_REQUEST {
if { [HTTP::path] eq "/" && not ([HTTP::uri] contains "#/login") } {
HTTP::redirect "https://example.com/content"
}
The not ([HTTP::path] contains "#/login") will exclude this URI from matching the first if statement. In other words the two conditions should be matched for the first if statement.
Read:
https://clouddocs.f5.com/api/irules/HTTP__uri.html
https://clouddocs.f5.com/api/irules/not.html
https://clouddocs.f5.com/api/irules/Operators.html
For basic irule knowedge you may check and I think you got the basic idea from what you have done so far:
https://devcentral.f5.com/s/articles/irules-101-01-introduction-to-irules
13-Apr-2021 00:49
It appears, browser is dropping anything coming after # in the URL. So "https://example.com/#/login" is ultimately being recieved at the BIGIP end as "https://example.com/" and you are right it would be redirected to "https://example.com/content" as it will match the 1st condition.
You would have to ask DEV team to change the URL for login or see if adding extra trailing slash (ie. https://example.com//#/login) would work or not.