Forum Discussion
abachman_72712
Nimbostratus
Aug 21, 2009Append to uri
I need to append to the uri that the user types. The client browser needs to see the addition for a certain java function to work properly. We are using an existing iRule for cookie persistence, and need to add to the existing iRule:
Here is the existing iRule:
when HTTP_RESPONSE {
if { [HTTP::cookie exists "JSESSIONID"] } {
persist add uie [HTTP::cookie "JSESSIONID"]
}
}
when HTTP_REQUEST {
log local0. "Request: [HTTP::uri]"
if { [HTTP::cookie exists "JSESSIONID"] } {
persist uie [HTTP::cookie "JSESSIONID"]
} else {
set jsess [findstr [HTTP::uri] "jsessionid" 11 ";"]
if { $jsess != "" } {
persist uie $jsess
}
}
}
Here is what I am trying to add into the iRule:
when HTTP_REQUEST { if {[HTTP::uri] starts_with "/cc/Claim"} {
HTTP::redirect http://[HTTP::host]/cc/Claim/Claim.do
}
}
Any help would be appreciated?
- L4L7_53191
Nimbostratus
You could consider:when HTTP_REQUEST { if {[HTTP::uri] starts_with "/cc/Claim"} { HTTP::uri /cc/Claim/Claim.do } }
- hoolio
Cirrostratus
As Matt suggested, if you want to redirect the client, you should do it before anything else in the HTTP_REQUEST event:when HTTP_REQUEST { log local0. "Request: [HTTP::uri]" if {[HTTP::uri] starts_with "/cc/Claim"}{ HTTP::redirect "http://[HTTP::host]/cc/Claim/Claim.do" } elseif { [HTTP::cookie exists "JSESSIONID"] } { persist uie [HTTP::cookie "JSESSIONID"] } else { set jsess [findstr [HTTP::uri] "jsessionid" 11 ";"] if { $jsess != "" } { persist uie $jsess } } } when HTTP_RESPONSE { if { [HTTP::cookie exists "JSESSIONID"] } { persist add uie [HTTP::cookie "JSESSIONID"] } }
- L4L7_53191
Nimbostratus
Aaron - good catch, thanks for clarifying this. Re-reading my original post this wasn't clear at all...sigh. - abachman_72712
Nimbostratus
Thanks guys. The URI is working and I can get to the logon screen with the modifications you suggested, but the user's browser still only shows http://cc/Claim. Is there a command I can add in to get the /claim.do to show up in the uri line of the user's browser. This is needed for the java piece to work. - L4L7_53191
Nimbostratus
Use the redirect method Aaron outlines above in that case. By using HTTP::uri we're quite literally redefining the URI just before it passes back to the server - so the client is clueless about the change. This is fairly effective as a resource cloaking trick but in your case it sounds like the 302 is the way to go. - L4L7_53191
Nimbostratus
Sorry: just to clarify, are you using the HTTP::uri method or the HTTP::redirect method? The post above shows a redirect but you mention that the URI is concealed from the client which implies using HTTP::uri. I fully expect the redirect to honor the URI and for it to be seen at the client...is this not the case? Can you capture some headers and paste them in so we can see the behavior? - abachman_72712
Nimbostratus
I believe I am using the HTTP::redirect method recommended, would you agree from the posted iRule? With the redirect syntax, the claim.do is not appearing in the client browser. - hoolio
Cirrostratus
If the client is making a request to /cc/Claim using the above iRule, they should get redirected to /cc/Claim/Claim.do. I'd guess either there is a mismatch in the URI listed in the rule versus what the client is requesting or the redirect is being made but the client isn't seeing it possibly because another redirect from the app. Can you add logging to the iRule and use a browser plugin as Matt was alluding to like HttpFox for Firefox or Fiddler for IE?when HTTP_REQUEST { log local0. "[IP::client_addr]:[TCP::client_port]: New [HTTP::method] request to [HTTP::uri]" if {[HTTP::uri] starts_with "/cc/Claim"}{ log local0. "[IP::client_addr]:[TCP::client_port]: Matched URI check, redirecting to http://[HTTP::host]/cc/Claim/Claim.do" HTTP::redirect "http://[HTTP::host]/cc/Claim/Claim.do" } elseif { [HTTP::cookie exists "JSESSIONID"] } { log local0. "[IP::client_addr]:[TCP::client_port]: jsessionid cookie exists, persisting with it." persist uie [HTTP::cookie "JSESSIONID"] } else { log local0. "[IP::client_addr]:[TCP::client_port]: Check for jsessionid in URI" set jsess [findstr [HTTP::uri] "jsessionid" 11 ";"] if { $jsess != "" } { log local0. "[IP::client_addr]:[TCP::client_port]: Found jsessionid in URI" persist uie $jsess } } } when HTTP_RESPONSE { if { [HTTP::cookie exists "JSESSIONID"] } { log local0. "[IP::client_addr]:[TCP::client_port]: Persisting based on response jsessionid cookie" persist add uie [HTTP::cookie "JSESSIONID"] } }
- L4L7_53191
Nimbostratus
I see you may have a redirect loop:when HTTP_REQUEST { if { [HTTP::uri] starts_with "/cc/Claim" } { HTTP::redirect "http://[HTTP::host]/cc/Claim/Claim.do" } }
when HTTP_REQUEST { if { [HTTP::uri] ends_with "/cc/Claim" } { HTTP::redirect "http://[HTTP::host]/cc/Claim/Claim.do" } if { [HTTP::uri] ends_with "Claim.do" } { HTTP::respond 200 content "You made it!!" } }
- hoolio
Cirrostratus
Nice catch, Matt. You could also use eq to check for an exact URI of /cc/Claim/ before redirecting:
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