Forum Discussion
Remove first element of uri
Hi,
I'm looking to remove the first element of a URI.
This is what I got from searching this site and it works.
when HTTP_REQUEST { if { [HTTP::uri] starts_with "/css" } { HTTP::uri [string map {"/css/" "/"} [HTTP::uri]] } }
I have to write a specific rule for every branch in the system ie
/css /apps /containers
Each branch goes to a separate pool and the web developers want to start at / rather than /css in each of the examples.
Is there a way to read the first element of the uri and then remove it in the rule. One rule will work with every branch.
Thanks
9 Replies
- arpydays
Nimbostratus
not quite sure I fully understand, is this the sort of thing you mean?
when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] { "/css*" { HTTP::uri [string map {"/css/" "/"} [HTTP::uri]] pool css } "/apps*" { HTTP::uri [string map {"/apps/" "/"} [HTTP::uri]] pool apps } "/containers*" { HTTP::uri [string map {"/containers/" "/"} [HTTP::uri]] pool containers } } } - paulfish
Nimbostratus
Hi,
Thanks for the fast response.
I think what you have written would work, I don't actually need to specify the string, I need to remove the first element, what ever it is.
I think this might work, I at home now so I will need to test tomorrow.
What do you think?
when HTTP_REQUEST { { HTTP::uri [string map {"/*/" "/"} [HTTP::uri]] } }
- GaganD
Nimbostratus
Hi There,
Paul is spot on. As you need to pick a different pool based on uri, you will need different statements for different uri, so that you can pick different pools. Maybe you can simplify it by moving the uri modification part of out of statement
when HTTP_REQUEST { set x [string tolower [HTTP::uri]] HTTP::uri [string map {"/*/" "/"} [HTTP::uri]] switch -glob x { "/css*" { pool css } "/apps*" { pool apps } "/containers*" { pool containers } } } ----------`
- Brad_Parker_139
Nacreous
Updated and tested in my lab, this could work for you.
when HTTP_REQUEST { set uri "/[getfield [HTTP::uri] "/" 2]/" HTTP::uri [string map " $uri / " [HTTP::uri]] }It will remove the first folder in the URI path.
- Brad_Parker_139
Nacreous
Pool selection can be done either with a switch or a datagroup. A datagroup will scale easier as you will just have to add all your root apps like css to the data group to have pool selection based on it. Switch: when HTTP_REQUEST { set uri "/[getfield [HTTP::uri] "/" 2]/" HTTP::uri [string map " $uri / " [HTTP::uri]] switch [getfield [HTTP::uri] "/" 2] { "css" - "apps" - "containers" { pool [getfield [HTTP::uri] "/" 2] } default { pool *default_pool* } } } Datagroup: when HTTP_REQUEST { set uri "/[getfield [HTTP::uri] "/" 2]/" HTTP::uri [string map " $uri / " [HTTP::uri]] if { [class match [getfield [HTTP::uri] "/" 2] equals *datagroupname*] }{ pool [getfield [HTTP::uri] "/" 2] } } - paulfish
Nimbostratus
Thanks everyone, very much appreciated
- Brad_Parker
Cirrus
Updated and tested in my lab, this could work for you.
when HTTP_REQUEST { set uri "/[getfield [HTTP::uri] "/" 2]/" HTTP::uri [string map " $uri / " [HTTP::uri]] }It will remove the first folder in the URI path.
- Brad_Parker
Cirrus
Pool selection can be done either with a switch or a datagroup. A datagroup will scale easier as you will just have to add all your root apps like css to the data group to have pool selection based on it. Switch: when HTTP_REQUEST { set uri "/[getfield [HTTP::uri] "/" 2]/" HTTP::uri [string map " $uri / " [HTTP::uri]] switch [getfield [HTTP::uri] "/" 2] { "css" - "apps" - "containers" { pool [getfield [HTTP::uri] "/" 2] } default { pool *default_pool* } } } Datagroup: when HTTP_REQUEST { set uri "/[getfield [HTTP::uri] "/" 2]/" HTTP::uri [string map " $uri / " [HTTP::uri]] if { [class match [getfield [HTTP::uri] "/" 2] equals *datagroupname*] }{ pool [getfield [HTTP::uri] "/" 2] } } - paulfish
Nimbostratus
Thanks everyone, very much appreciated
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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