Forum Discussion
iRule which check uri or path contains
I need to do iRule which check uri or path and send traffic to different pools, and when client try connect to "testweb.com/api/app/1/workstation-params/100" it wiil go to "testweb.com/api/app/workstation-params/100" and pool "pool1"
When client try "/api_aaa" - go to pool "pool2"
When try only "testweb.com/" - go to pool "pool2"
I have irule, but it doesn't work correctly.
when HTTP_REQUEST {
if { [HTTP::uri] contains "/api/app/1/" } {
HTTP::path "/api/app/"
}
elseif { [HTTP::uri] contains "/api/app/" } {
pool pool1
}
elseif { [HTTP::path] equals "/api_aaa"} {
pool pool2
} else {
pool pool2
}
}
5 Replies
- Joel_Breton
Nimbostratus
Hi,
You can try a switch case
when HTTP_REQUEST { set myuri [HTTP:uri] switch -glob [string tolower $myuri]{ "/api/app/1/" { HTTP:path "/api/app/" pool pool1 } "/api/app/" { pool pool1 } "/api_aaa" { pool pool2 } else { pool pool2 } }
- crodriguezRet. Employee
The HTTP::path "/api/app/" statement in your code is replacing the entire path with the value specified, not just the /api/app/1/ part. As a result, your path is changing from /api/app/1/workstation-params/100, for example, to just /api/app/, and dropping the workstation-params/100 part. To replace just the portion of the path string that needs to change and, more importantly, also select pool1, you could try something like this:
when HTTP_REQUEST { if { [string tolower [HTTP::uri]] contains "/api/app/1/" } { HTTP::uri [string map { "/api/app/1/" "api/app/" } [string tolower [HTTP::uri]] pool pool1 } elseif { [string tolower [HTTP::uri]] contains "/api/app/" } { pool pool1 } else { pool2 } }
I don't see the need to check for "/api_aaa" separately as the last elseif and else conditions in your original code both do the same thing which is to select pool2 - but I could be missing something.
- Volodymyr_32240
Nimbostratus
Thx for help!
- Danny_Cabrera_3
Nimbostratus
Hello all
I have the following case: If an URL contains: /wps/XMLServlet or /wps/pages/redirect.aspx, not do anything, else redirect to: https://www.mysite.com
My irule is the following
when HTTP_REQUEST { if { ([HTTP::uri] contains "/wps/XMLServlet") or [HTTP::uri] contains "/wps/pages/redirect.aspx")}{ } else { HTTP::redirect ";} }
When I try the irule with: https://www.abc.com/wps/XMLServlet or https://www.abc.com/wps/pages/redirect.aspx, it works well, but when I try: http://www.abc.com/wps/XMLServlet or http://www.abc.com/wps/pages show me the error: The connection was reset
¿Could you help me with this problem?
Hi Danny,
I noticed that from what you have stated, only the
URLs are working; when you try to test with theHTTPS
URLS you get a TCP reset. Correct?HTTP
Could you confirm that you have a virtual server configured listening on port 80 which also has this iRule applied? (NOTE: this virtual server should NOT have any client or server SSL profiles applied)
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