Forum Discussion
nested elseif unexpected behaviour
I created an iRule to (first) redirect to maintenance page and then if available redirect traffic to 1 of 3 pools based on URI data groups. The iRule compiles fine but the result is unexpected. The correct home page comes up but is missing parts and if I try any of the links the lead nowhere and the home page remains.
New rule:
when HTTP_REQUEST {
if { [active_members INF-HEC-HTTP] < 1 } {
switch -glob [string tolower [HTTP::path]] {
"_.gif" -
"_.css" {
HTTP::uri [string range [HTTP::uri] [string last / [HTTP::uri]] end]
}
default {
HTTP::uri /
}
}
pool QA-PH
} elseif { [class match [string tolower [HTTP::uri]] starts_with QA-HEC-ENT-URI] } {
pool INF-ENT-HTTP
} elseif { [class match [string tolower [HTTP::uri]] starts_with QA-HEC-URI] } {
pool INF-HEC-DNNREDIRECT
} else {
pool INF-HEC-HTTP
}
}
Old rule that works except for maintenace: and no uri
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::uri]] {
"/ent/*" -
"/"
{ pool QA-ENT-HTTP
return
}
}
switch -glob [string tolower [HTTP::uri]] {
"/site_includes/_" -
"/backoffice_newer_" -
"/emp_banner/_" -
"/media_kits/" -
"/promo/_" -
"/adproducts/" -
"/cst/ui/_" -
"/cst/backoffice/_" -
"/employer_" -
"/employer/" -
"/js-old/_" -
"/employer\asp" -
"/site_templates/_" -
"/assoclist.asp_"
{
pool QA-HEC-HTTP-DNNREDIRECT
}
default
{
pool QA-HEC-HTTP
}
}
}
- Kevin_StewartEmployee
Gotcha. So just to be clear, if the www.website.com page references an image like this:
/images/my_cat.jpg
The maintenance web server would have the same image, but at:
/my_cat.jpg
Is that correct?
- ryan_rockwell_1Nimbostratus
Nope. The maintenance page has it's own set of images that reside on the server in the QA-PH pool. Completely different server.
- Kevin_StewartEmployee
Thought so. So when you respond to the client with the content of the maintenance page, the image links within that page will be relative to that website. You should therefore not have to translate the URI of the image in your code. So for example, if the maintenance page contains an image link for /images/foo/bar/my_puppy.jpg, you want the client to request this exact URI (under the maintenance condition).
- ryan_rockwell_1Nimbostratus
I would think but for some reason it doesn't work that way. If I take out this section:
switch -glob [string tolower [HTTP::path]] { "*.gif" - "*.jpg" - "*.css" { HTTP::uri [string range [HTTP::uri] [string last / [HTTP::uri]] end] } default { HTTP::uri / } }
My maintenance page comes up fine, images and all on http://www.website.com but when I go to http://www.website.com/login I get a 404 page not found. If I leave the section in I get the the maintenance page on both url's but missing the images.
- Kevin_StewartEmployee
Okay, so try this:
switch -glob [string tolower [HTTP::path]] { "*.gif" - "*.jpg" - "*.css" { return } default { HTTP::uri / } }
If the URI is for an image or css, let it through and leave it alone. Otherwise change the URI to /.
- ryan_rockwell_1Nimbostratus
Unfortunately no love. I misrepresented my earlier findings. With "HTTP::uri [string range [HTTP::uri] [string last / [HTTP::uri]] end]" I get the css page but not the images. without I do not get the css or images. Server 404.
- ryan_rockwell_1Nimbostratus
Additional info. styles.css is in root directory and gif's are in root/images directory.
- Kevin_StewartEmployee
Try this:
log local0. "request URI = [HTTP::uri]" switch -glob [string tolower [HTTP::path]] { "*.gif" - "*.jpg" - "*.css" { return } default { HTTP::uri / } }
Take a look at the URIs that the client is requesting. Are they correct?
- ryan_rockwell_1Nimbostratus
Rule /Common/INF-HEC-LB-URI-HTTP : incoming URI = / Rule /Common/INF-HEC-LB-URI-HTTP : sending to QA-PH Rule /Common/INF-HEC-LB-URI-HTTP : incoming URI = /styles.css Rule /Common/INF-HEC-LB-URI-HTTP : sending to QA-PH Rule /Common/INF-HEC-LB-URI-HTTP : incoming URI = /styles.css Rule /Common/INF-HEC-LB-URI-HTTP : sending to QA-PH Rule /Common/INF-HEC-LB-URI-HTTP : incoming URI = /images/construction.gif Rule /Common/INF-HEC-LB-URI-HTTP : sending to QA-PH Rule /Common/INF-HEC-LB-URI-HTTP : incoming URI = /images/header.jpg Rule /Common/INF-HEC-LB-URI-HTTP : sending to QA-PH
Which I would say is correct but it doesn't display correct. Wonder if it has to do with the leading "/" again?
- Kevin_StewartEmployee
Wonder if it has to do with the leading "/" again?
I can't imagine that's true. Can you open a browser and go directly to the maintenance server? And if so, can you try the /images/header.jpg URI directly?
Worst case, do a server side tcpdump capture and see what the URIs actually look like on the way to the maintenance server.
tcpdump -lnni 0.0 -Xs0 host x.x.x.x
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