Forum Discussion
Mike_Graston_10
Nimbostratus
Jan 26, 2007Adding a uri if one doesn't exist
Currently I have a url split between several pools depending on uri portion. How would I modify the Irule to insert a uri if none is present?Any help would be appreciated...
when HTTP_REQUEST {
if { [string tolower [HTTP::uri]] starts_with "/abc"} {
pool mywebsite.com-abc
}
elseif { [string tolower [HTTP::uri]] starts_with "/def"} {
pool mywebsite.com-def
}
else {
pool mywebsite.com-ghi
}
}
Now if it request comes in with just the url domain name and does not have a /* after it I want to add the /ghi/ to it?
Sort of stumped but does appear to seem it would be too difficult to do????
11 Replies
- Wil_Schultz_101
Nimbostratus
This should get you there!elseif { [string tolower [HTTP::uri]] equals "/"} { HTTP::respond 301 "Location" "http://my.domain.tld/ghi" } - Colin_Walker_12Historic F5 AccountUnless I'm mis-interpreting the request, the HTTP::respond command isn't going to produce the desired results. The HTTP::respond command is going to send a response to the client, whereas I believe what xf6svrb is looking for is to modify the client's originally requested URI, if it's empty, to contain "ghi". Is that correct?
If so, you'd want logic something like this:when HTTP_REQUEST { if { [string tolower [HTTP::uri]] starts_with "/abc"} { pool mywebsite.com-abc } elseif { [string tolower [HTTP::uri]] starts_with "/def"} { pool mywebsite.com-def } else { if { [string length [HTTP::uri] < 2] } { HTTP::uri "/ghi/" } pool mywebsite.com-ghi } }
HTH,
Colin - Mike_Graston_10
Nimbostratus
Guys,
thanks for the input but I must be doing something wrong. The first way with the 301 the irule took and I was able to insert it in the rule. It did not work as far as responding back to the browser, I just got the usual message of 403 forbidden. The second attempt I made would not allow me to add the < 2 command as the irule wouldn't except the syntax. I tried a combination of the two with respect to the uri.
Ths syntax error is
line 2: [wrong args] [string length [HTTP::uri] < 2]
Sorry I tried a couple different thing and they don't seem to be working... - Leo_Katona_5507
Nimbostratus
The line:if { [string length [HTTP::uri] < 2] } {
should read:if { [string length [HTTP::uri]] < 2 } {
-Leo - Mike_Graston_10
Nimbostratus
Thanks, that corrected the syntax error I was seeing and should have picked up on! This didn't append the /ghi/ like expected. I changed the rule to have just this in and still didn't get it to work.
when HTTP_REQUEST {
if { [string length [HTTP::uri]] < 2 } {
HTTP::redirect "https://mysite/ghi/"
}
else {
pool www-mypool-ghi
}
}
Also tried
elseif { [string tolower [HTTP::uri]] equals "/"} {
HTTP::respond 301 "Location" "http://mysite/ghi"
}
Also tried:
if { [string length [HTTP::uri]] < 2] } {
HTTP::uri "/ghi/"
}
Also got this from the wikis:
when HTTP_REQUEST {
if { not ([HTTP::uri] starts_with "/ghi/") } {
HTTP::uri /ghi/[HTTP::uri]
}
}
Nothing seems to be working to appen the /ghi/???
Driving me nuts! - Leo_Katona_5507
Nimbostratus
Does this work:when HTTP_REQUEST { if {[string equal [HTTP::uri] {/}] } { HTTP::uri {/ghi/} } }
If it doesn't, change the "Type" configured for the virtual server to "Standard" and retry.
Also, was it clear to you that this causes BIG-IP to modify the HTTP request passing from the user to the server? Therefore, even though the content is coming from http://www.example.com/ghi/, the user's web browser will still show http://www.example.com/ in the address field.
-Leo - Mike_Graston_10
Nimbostratus
No, this didn't seem to work ever though this is my only entry in the Irule
when HTTP_REQUEST {
if {[string equal [HTTP::uri] {/}] } {
HTTP::uri {/ghi/}
}
}
It still won't append it???? I would then expect at the browser to see a redirect to the actual login page as there are redirects on the web server that would redirect to the login.jsp. I am now stumped!!! The VS type = standard. - Leo_Katona_5507
Nimbostratus
The latest simplified rule *will* work if configured correctly, so could you check
a) that the iRule is configured for the correct virtual server on the BIG-IP;
b) your web server logs to see what requests the server is actually receiving;
c) whether you get redirected to the login.jsp page by your web server if you access the http://www.example.com/ghi/ address directly;
d) which version of the BIG-IP software you're using.
-Leo - The only way to test this is to include logging statements on the BIG-IP as well as web server logging on the backend server.
when HTTP_REQUEST { log local0. "URI: [HTTP::uri]" if { [HTTP::uri] equals "/" } { log local0. "URI is empty, changing to http://[HTTP::host]/ghi..." HTTP::uri "/ghi/" } else { log local0. "URI is not empty, leaving alone..." } }
Then look in the /var/log/ltm file on the BIG-IP to make sure that the iRule is functioning correctly. If you see that is the case, then you'll have to look at the web server's log (or a packet trace) on the web server to verify the GET request is now "/ghi/". If your webserver is still showing a "GET / ..." then you'll have to contact Technical support as this is very basic functionality and you are using the iRule correctly.
-Joe - JRahm
Admin
log "log this ..."
or
log local0. "log this ..."
go to the file /var/log/ltm (on an LTM system)
You can check your syslog-ng.conf file for the other facilities.
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects
