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
- 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] }
- 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 hereset val [getfield [HTTP::uri] "/" 2]
- Esa_Kuusisto_27
Nimbostratus
Yeah, that helps a lot.
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