Forum Discussion
Dachicourt_Fabi
Nimbostratus
Jan 07, 2005Using format strings in version 9
the string %h %p et %u don't work on version 9
for exemple, a rule like
rule my_rule {
if ([HTTP::uri] ends_with "baz") {
redirect to "https://%h:8080/%u/"
}
else {
use pool web_pool
}
}
don't work anymore.
Do you know a way to do this in version 9 ?
9 Replies
- unRuleY_95363Historic F5 AccountThese special format strings were dropped because it would require unnecessary changes to the native Tcl processing. Instead, simply use the '[' ']' evaluation and the appropriate F5 Tcl command. Here's what your rule would look like:
rule my_rule { when HTTP_REQUEST { if { [HTTP::uri] ends_with "baz" } { redirect to "https://[HTTP::host]:8080/[HTTP::uri]/" } else { use pool web_pool } } } - For those interested, the F5 TCL commands are documented in the user manual as well as in the Docs and Tips section of DevCentral. The tip on "Querying Header and Content Data" can be found here:
http://devcentral.f5.com/Default.aspx?TabID=29&newsType=ArticleView&articleId=32
-Joe - Brian_Gupta_115
Nimbostratus
Joe,
Based on the doc you listed, I constructed the following rule:when HTTP_REQUEST { redirect to "https://[URI::host][HTTP::uri]" }
That gave me a syntax error. I played around and came up with this:when HTTP_REQUEST { redirect to "https://[HTTP::host][HTTP::uri]" }
Are the URI::xxx commands listed valid? Or am I just using them incorrectly?
Thanks,
Brian - drteeth_127330Historic F5 AccountThe URI commands can be used to extract individual field components from a URI. For example,
should be equivalent to[URI::query [HTTP::uri]]
However, the protocol, host, and port commands are only meaningful when used with a full URI, e.g. http://www.foo.com/bar.html. This is the problem that you encountered.[HTTP::query] - bl0ndie_127134Historic F5 AccountHTTP::uri returns the URI that is sent on the GET/POST request. This normally means that it will not have the protocol or host strings, at least not in the same way the user may have typed into the user agent. The exception being proxy requests, which will have the full URI.
We added bunch of utility of functions that make the URI parsing easy, please see below for the brief explanations. One thing to note though, after a long discussion with rapMaster_c, drTeeth, unRuly (last names omitted as a professional courtesy), we decided to chose ‘URI::path’ to carry the spirit of UNIX where you need to use ‘basename’ and path to get the actual document. There is a good example of this on one of my earlier postings for making BigIP behave like an http proxy. Here is the link to the posting … http://devcentral.f5.com/default.aspx?tabid=28&view=topic&forumid=5&postid=1332URI::protocol Extracts the protocol part from the URI string that you specify. URI::basename Extracts the basename part from the URI string that you specify. URI::path Extracts the path from the URI string that you specify. URI::query Extracts the query part from the URI string that you specify. URI::host Extracts the host part from the URI string that you specify. URI::compare Compares URIs as recommended by RFC 2616 section 3.2.3. URI::decode Returns the decoded URI string. URI::encode Returns the encoded URI string URI::port Extracts the port part from the URI string that you specify. - Brian_Gupta_115
Nimbostratus
One thing that confused me is your terminology. In "web" terminolgy I thought a URL consisted of protocol://hostname:port/uri
It seems you use the term URI consistently to refer to a URL. In your terminology a URI consists of protocol://basename:port/path?query vs just path?query
Is my understanding of your terminology correct?
Thanks,
Brian - rapmaster_c_127Historic F5 AccountI'm not sure I agree with you. Here's a website that sums up our take on URI vs URL vs URN.
http://www.pierobon.org/iis/url.htm - Loc_Pham_101863Historic F5 AccountFurther clarifications/recommendations by W3C on URI vs. URL vs. URN. Note the Contemporary View.
http://www.w3.org/TR/uri-clarification/
Loc - Brian_Gupta_115
Nimbostratus
Thanks for the clrification.
-Brian
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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
