Forum Discussion
URI redirect iRule review/Help
Hello Guys, I have a question or review request for the below iRule. let me tell you about the requirement first. The user needs redirect to any URI that starts with /monkey/* BUT does not want 2 URL's which has /monkey/ to be redirected.
Like do not redirect
https://main.you.com/monkey/std/public/v1
and
https://main.you.com/monkey/public/v2
But redirect any other URL that has URI - /monkey/*
The iRule that I came up with and does not work is below. What am I doing wrong?
when HTTP_REQUEST {
if { ([string tolower [HTTP::host]] eq "main.you.com") and ([string tolower [HTTP::uri]] eq "/monkey/std/public/v1") } {
HTTP::redirect "https://main.you.com/monkey/std/public/v1"
}
elseif { ([string tolower [HTTP::host]] eq "main.you.com") and ([string tolower [HTTP::uri]] eq "/monkey/public/v2") } {
HTTP::redirect "https://main.you.com/monkey/public/v2"
}
elseif { [string tolower [HTTP::host]] eq "main.you.com" } and ([string tolower [HTTP::uri]] eq "/monkey/*") } {
HTTP::redirect "https://side.you.com"
else { use pool main.you.com_pool
}
}
- Samir_Jha_52506
Noctilucent
Did some modification in irule. Either use
place ofstart_with or contains
in syntex. It will work. Please let us know if any issueeq
when HTTP_REQUEST { if { ([string tolower [HTTP::host]] eq "main.you.com") and ([string tolower [HTTP::uri]] starts_with "/monkey/std/public/v1") } { HTTP::redirect "https://main.you.com/monkey/std/public/v1" } elseif { ([string tolower [HTTP::host]] eq "main.you.com") and ([string tolower [HTTP::uri]] starts_with "/monkey/public/v2") } { HTTP::redirect "https://main.you.com/monkey/public/v2" } elseif { ([string tolower [HTTP::host]] eq "main.you.com") and ([string tolower [HTTP::uri]] starts_with "/monkey/*") } { HTTP::redirect "https://side.you.com" } else { pool main.you.com_pool } }
- Domai
Altostratus
Thank you f5_rock I tried contains or start_with it did not work. It goes into a loop.
- Nandhini_Natara
Nimbostratus
Hello Domai,
Please try with below irule
when HTTP_REQUEST {
if { ([string tolower [HTTP::host]] starts_with "main.you.com") and ([string tolower [HTTP::uri]] starts_with "/monkey/std/public/v1") } { HTTP::redirect "[https://main.you.com/monkey/std/public/v1"](https://main.you.com/monkey/std/public/v1); } elseif { ([string tolower [HTTP::host]] starts_with "main.you.com") and ([string tolower [HTTP::uri]] starts_with "/monkey/public/v2") } { HTTP::redirect "[https://main.you.com/monkey/public/v2"](https://main.you.com/monkey/public/v2); } elseif { ([string tolower [HTTP::host]] starts_with "main.you.com") and ([string tolower [HTTP::uri]] starts_with "/monkey/") } { HTTP::redirect "[https://side.you.com"](https://side.you.com); } else { pool main.you.com_pool }
}
- Domai
Altostratus
Nandhini I tried that with both "starts_with" and "contains" it did not work as intended. Jie's iRule did work.
- JG
Cumulonimbus
I hope this is what you need:
when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "main.you.com" } { switch -glob [string tolower [HTTP::path]] { "/monkey/std/public/v1*" - "/monkey/std/public/v2*" { pool main.you.com_pool } "/monkey/*" { HTTP::redirect "https://side.you.com/" } default { pool main.you.com_pool } } } }
- Proba_360838
Nimbostratus
great help
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