22-Nov-2022 13:20
I am fairly new to iRules so any help greately appreciated.
What is correct syntax to exclude URI "/abc/Web123/cde/forum123/ from receiving HTTP code 200 and the message "123456789"? Is the exclamation mark a orrect synatx to exclude URI?
Here is iRule
when HTTP_REQUEST {
set http_path [ string tolower [HTTP::path]]
if { ! ($http_path starts_with "/abc/Web123/cde/forum123") } {
HTTP::respond 200 content "
<html>
<head>
<title></title>
</head>
<body>
123456789
</body>
</html>
"
}
}
Thank you for any assistamce you can provide.
Solved! Go to Solution.
23-Nov-2022 06:54
To negate starts_with I would use the not operator:
https://clouddocs.f5.com/api/irules/not.html
when HTTP_REQUEST {
if { not ([HTTP::uri] starts_with "/abc") } {
# do something ...
} else {
# do something else...
}
}
For excluding the exact path, you can go with the "ne" operator
22-Nov-2022 22:42
As far as i know you can use ! or NOT.
Here are the operators list:
https://clouddocs.f5.com/api/irules/Operators.html
23-Nov-2022 05:46
Hi @Alex_Pintel ,
Could you please try this :
when HTTP_REQUEST {
#set http_path [ string tolower [HTTP::path]]
if { [HTTP::path] ne "/abc/Web123/cde/forum123" } {
HTTP::respond 200 content "
<html>
<head>
<title></title>
</head>
<body>
123456789
</body>
</html>
"
}
}
I tested it on my lab and it works well.
Regards
23-Nov-2022 05:21 - edited 23-Nov-2022 05:23
Hello, if you're looking to exclude an exact match for a string, "ne" operator can be used as well.
One thing I noticed -- since this is an exact match, be careful with "string tolower" syntax as it will convert everything to lowercase, so you will never see Web123 -- it's gonna be web123 instead.
I generally don't recommend converting paths to lowercase since it is case sensitive, try using this instead:
if { [HTTP::path] ne "/abc/Web123/cde/forum123" }{ ... }
23-Nov-2022 09:08
Thank you all for responding to my post. I have another question.
What would be right syntax if I need to use 2 URLs?
if { [HTTP::path] ne "/abc/Web123/cde/forum123" OR "/abc/Web123/cde/forum456"
Is the "OR" correct operator?
Thank you!
24-Nov-2022 00:08
For the requested logic, you need the "and" operator between two tests:
if { ([HTTP::path] ne "/abc/Web123/cde/forum123") and ([HTTP::path] ne "/abc/Web123/cde/forum456") }
If you plan to add more paths in the future, then consider using a switch test
23-Nov-2022 06:54
To negate starts_with I would use the not operator:
https://clouddocs.f5.com/api/irules/not.html
when HTTP_REQUEST {
if { not ([HTTP::uri] starts_with "/abc") } {
# do something ...
} else {
# do something else...
}
}
For excluding the exact path, you can go with the "ne" operator