Forum Discussion
iRule - Prepend Path to URI
Hoping someone can point me in the right direction...
I need to prepend /abc to all requests to www.host.com. I cannot use redirects.
Request: www.host.com/testing
Needs to hit the server as: www.host.com/abc/testing
I was thinking this may work but it doesn't:
if { [HTTP::host] starts_with "www.host.com"}{ HTTP::uri [string map {"[HTTP::uri]" "/abc[HTTP::uri]"} [HTTP::uri]] }
Any help is much appreciated!
For reasons I can't explain, string map is not matching [HTTP::uri]
Since this is a simple prepend, you could do this instead
when HTTP_REQUEST { if { [HTTP::host] starts_with "www.host.com"}{ HTTP::uri "/abc[HTTP::uri]" } }
- mimlo_61970Cumulonimbus
For reasons I can't explain, string map is not matching [HTTP::uri]
Since this is a simple prepend, you could do this instead
when HTTP_REQUEST { if { [HTTP::host] starts_with "www.host.com"}{ HTTP::uri "/abc[HTTP::uri]" } }
- mimlo_61970CumulonimbusApparently curly braces prevent string expansion in TCL? https://devcentral.f5.com/s/feed/0D51T00006j4QMgSAM Try HTTP::uri [string map "[HTTP::uri] /abc[HTTP::uri]" [HTTP::uri]]
- mtobkes_64700NimbostratusThanks mimlo, that's exactly what I was looking for! No need to perform string map. Thanks
What if I want exactly the opposite. I want the VS which is http://10.50.170.1:80/test/Services/SecureAdapters/AndroidWidget/Interface/GetMSISDNAndBundleInformation-SOAP
should hit the pool as
http://10.50.169.14:11040/Services/SecureAdapters/AndroidWidget/Interface/GetMSISDNAndBundleInformation-SOAP
http://10.50.169.16:11040/Services/SecureAdapters/AndroidWidget/Interface/GetMSISDNAndBundleInformation-SOAP
For example the above pool name is F5. I want iRule to select this pool on the URI /test but remove the word /test when send to pool.
- mimlo_61970Cumulonimbus
In its simplest form, that would be
when HTTP_REQUEST { HTTP::uri [string map {"/test" "" } [HTTP::uri]] }
Not sure if you need to make sure it starts with /test, or only applies to some host headers or what not, but that will remove /test from the URI
- Great but not only I want to remove it from the URL but I want to select a pool on the basis of /test. Just like proxypass works in Apache. It decides a pool on the basis of first word in URL like http://10.50.171.8:80/test/Services..................... now VS will select a pool name TEST(or what ever) and omit the work /test from the url and send it to pool TEST. I will be always grateful if you combine this with your last comment.
- mimlo_61970Cumulonimbus
This should remove the /test and select the pool POOL_NAME
when HTTP_REQUEST { set uri [string tolower [HTTP::uri]] if { $uri starts_with "/test" } { HTTP::uri [string map {"/test" "" } $uri ] pool POOL_NAME } }
- As my URl are case sensitive so made little change when HTTP_REQUEST { set uri [HTTP::uri] if { $uri starts_with "/CRM" } { HTTP::uri [string map {"/CRM" "" } $uri ] pool Tibco-LB-Group4 } } This is working for me Please check if the set statement is right? Please can you add a statement which will log all the requests to external log server for example the ip of the log server is 10.50.242.239. You made my day sir.
- I only want to remove /CRM at the start of URI and if it occurs again in the URL iRule should not remove it it. How can i do that. final requirement. Please
- kunjanNimbostratusset index [string first "/CMS" [HTTP::uri]] set uri [string replace [HTTP::uri] $index [expr $index+4] ] HTTP::uri $uri
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