Forum Discussion
Need help with iRule based on host and path
- Jul 11, 2024
Finally, problem solved! The reason was the order of execution for the 2 scripts. I donot really understand why this happens but when I placed the script in second place, everything is executed as expected. If you have any ideas please let me know.
The problematic order which doesnot work is shown below:
First script:
when HTTP_REQUEST {
if { [HTTP::host] equals "hostname_a"} {
if { [HTTP::path] equals "/path" } {pool pool_a
log local0. "URL : [HTTP::host][HTTP::uri] entered"
}
}
if { [HTTP::host] equals "hostname_b"} {
if { [HTTP::path] equals "/path" } {pool pool_b
log local0. "URL : [HTTP::host][HTTP::uri] entered"
}
}
}Second script:
when HTTP_REQUEST {
if {[HTTP::has_responded]}{return}
switch -glob [string tolower [HTTP::path]]
{....
....
}
default
{
switch [string tolower [HTTP::host]]
{"hostname_a"
{
pool pool_c
persist none}
....
.....
default
{
pool_z
}
......
Anyway, thank you all very much for your time.
Can u try with below example, u can add specific uri and host name. u can edit it based on your different host and path
when HTTP_REQUEST {
# Define pool selection based on host and path
if { [HTTP::host] eq "example.com" } {
if { [HTTP::uri] starts_with "/app1" } {
pool pool_app1
} elseif { [HTTP::uri] starts_with "/app2" } {
pool pool_app2
} else {
pool default_pool
}
} elseif { [HTTP::host] eq "anotherexample.com" } {
if { [HTTP::uri] starts_with "/service1" } {
pool pool_service1
} elseif { [HTTP::uri] starts_with "/service2" } {
pool pool_service2
} else {
pool default_pool
}
} else {
# Fallback to a default pool if no match is found
pool default_pool
}
}
Thank you. Tried it, same result.
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com