Forum Discussion
Esa_Kuusisto_27
Nimbostratus
Nov 21, 2007Best way to get one part of the url to variable
Hi all
I have problem getting one part of the url to variable. I need example test variable and contents of the variable I can get from url. I always need the first part from the url between slashes.
Example /sales/office
I need to get that sales. I did try using string range, but I didn't find any way else to limit how much get from url than giving end-command or index number. If I replace sales with marketing or something else longer or shorter I cannot use static index number.
-Esa
4 Replies
- Esa_Kuusisto_27
Nimbostratus
Never mind.. Rethinking with regexp. - hoolio
Cirrostratus
If you want to just replace one string in the URI with another, you could use string map (Click hereπwhen HTTP_REQUEST { HTTP::uri [string map {find replace} [HTTP::uri] }
A string command would be more efficient than a regex based one.
Aaron - Regexps are bad if you absolutely don't need them. They are very resource intensive and in most cases, there are better alternatives. If you want to extract a field from a string separated by delimiters, you can use the iRule getfield command.
http://devcentral.f5.com/wiki/default.aspx/iRules/getfield.html
Click here
For your example URI of "/sales/office" The following commmand would extract the field "sales".set val [getfield [HTTP::uri] "/" 2]
This command extracts the specified field from the URI which is delimited by slashes "/". The first field would be the value before the first delimeter. In the case of a URI, it will always be an empty string. The second delimiter would be the value "sales", the third "office" and so on...
Hope this helps...
-Joe - Esa_Kuusisto_27
Nimbostratus
Yeah, that helps a lot.
Thank you.
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
