Forum Discussion
BigIP_Support_9
Nimbostratus
Nov 17, 2005forward URI with manipulation
We have an application with several modules for each dept. Each module is handled by a dedicated server. The application use URI to identify the module:
http://www.abc.com/sales/func1/index.jsp (will forward to a pool with member 10.1.1.1:7780)
http://www.abc.com/cs/func1/index.jsp (will forward to a pool with member 10.1.1.1:7790)
http://www.abc.com/it/func1/index.jsp (will forward to a pool with member 10.1.1.1:7800)
http://www.abc.com/logistics/func1/index.jsp (will forward to a pool with member 10.1.1.1:7810)
I use below to identify the modules
when HTTP_REQUEST {
if { [HTTP::uri] starts_with "/sales" } {
pool sales_pool
} else {
if { [HTTP::uri] starts_with "/cs" } {
pool cs_pool
} else {
...
}
}
}
However all the servers are running Oracle 9ias with context root func1. They don't have a root path begins with "sales", "cs", "it", or "logistics". They only accept
http://10.1.1.1:7780/func1/index.jsp
http://10.1.1.1:7790/func1/index.jsp
http://10.1.1.1:7800/func1/index.jsp
http://10.1.1.1:7810/func1/index.jsp
When I use the above irule to forward to the server pool, the URI is kept unchanged (eg GET /sales/func1/index.jsp HTTP/1.1), which is "page not found" on the servers. I need to remove the first level folder in the URI.
Is there a way to manipulate the URI before I forward it to corresponding pools?
- This is actually easier than it sounds. You can use the standard TCL string command (Click here) to extract everything including and past the second slash. Then use the HTTP::uri command to change the URI. I'm sure there are other ways to do this but this should work for you.
when HTTP_REQUEST { strip first directory from uri. ie. /foo/bar/foobar.ext -> /bar/foobar.ext set sub_uri [string range [HTTP::uri] [string first {/} [HTTP::uri] 1] end] if { [HTTP::uri] starts_with "/sales" } { pool sales_pool HTTP::uri $sub_uri } elseif { [HTTP::uri] starts_with "/cs" } { pool cs_pool HTTP::uri $sub_uri } else { do something else } }
set sub_uri [string range [HTTP::uri] [string first {/} [HTTP::uri] 1] end]
Find index of first slash searching from position 1 (2nd char) set idx [string first {/} [HTTP::uri] 1] Get substring from uri starting at location of second slash to the end set sub_uri [string range [HTTP::uri] $idx end]
- BigIP_Support_9
Nimbostratus
Thanks Joe. There is a minor issue with the URI manipulation. Below both URL should have the first directory removed, but only the second works..... ....
- Ok, you didn't mention that you needed the directory truncated if there wasn't a second slash. My previous example assumed that if there was only one directory, then it would remain.
when HTTP_REQUEST { set idx [string first {/} [HTTP::uri] 1] if { $idx != -1 } { set sub_uri [string range [HTTP::uri] $idx end] } else { set sub_uri {/} } ... HTTP::uri $sub_uri }
- BigIP_Support_9
Nimbostratus
Sorry that I can't find the item "modify uri and rewrite" in the list. Can you give me more details? Thansk. - Colin_Walker_12Historic F5 AccountI'm pretty sure Joe was talking about this post to his blog:
- BigIP_Support_9
Nimbostratus
I think the one we can use is the last one with "RESPONSE_DATA".........
- The example I provided does replace the FQDN and not the URI, but the concept is the same. Basically all we can do within the response data is do straight string replacement. You can do some smart parsing with the content looking for link, img, a, etc elements and then look for the corresponding href's or src's. Then extract the contents within. Basically if you get to this point you are building your own HTML parser within iRules which will more than likely be a big performance hog.
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