Forum Discussion
Benjamin_9120
Nimbostratus
May 30, 2010about regular expressions
Customer will access follow uri:
http://www.test.com/server1
http://www.test.com/server2
......
http://www.test.com/serverN
I want redirect to relate resource base on ser...
hoolio
Cirrostratus
May 30, 2010Hey CB,
I think you'd want to strip the leading forward slash from the URI. Also, you might want to take just the server to form the pool name:
when HTTP_REQUEST {
Check if Host is www.test.com and URI starts with /server
if { ([HTTP::host] eq "www.test.com") and ([HTTP::uri] matches_glob {/server[0-9]*}) } {
log local0. "[IP::client_addr]:[TCP::client_port]: Parsed [string range [HTTP::uri] 1 7] from [HTTP::uri]"
Select the pool, taking just server from the URI
pool pool_[string range [HTTP::uri] 1 7]
}
}
Or if you're not on 10.x and can't use matches_glob, you can use string match:
when HTTP_REQUEST {
Check if Host is www.test.com and URI starts with /server
if { ([HTTP::host] eq "www.test.com") and ([string match {/server[0-9]*} [HTTP::uri]]) } {
log local0. "[IP::client_addr]:[TCP::client_port]: Parsed [string range [HTTP::uri] 1 7] from [HTTP::uri]"
Select the pool, taking just server from the URI
pool pool_[string range [HTTP::uri] 1 7]
}
}
To do a redirect, you could replace the pool command with
HTTP::redirect "http ://www.example.com[HTTP::uri]"
or maybe something like
HTTP::redirect "http ://www.example.com[string range [HTTP::uri] 0 7]"
Aaron
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
