Forum Discussion
mattboston_5893
Nimbostratus
Apr 11, 2011Different pool depeding on the URI
With the F5 is it possible to send all traffic for www.domain.com to a default pool, but when someone requests www.domain.com/images it goes to a special images pool of servers?
Thanks
Matt
7 Replies
- Pconlan_71037
Altocumulus
Yes. We do something like this:
when HTTP_REQUEST {
use tolower to make the match case-insensitive
switch -glob [string tolower [HTTP::path]] {
"/images/*" {
pool ImagesPool
}
"/js/*" {
pool JsPool
}
etc.
etc.
default {
pool defaultPool
}
}
}
The URI gets compared to the strings you specify, and if it matches, the request gets sent to specified pool. If it doesn't match any of them it falls through to the pool specified in the default clause. - mattboston_5893
Nimbostratus
All of our existing rules use if/elseif/else and do matches like the following (trimmed down). Is it possible to do what you said using the existing if/elseif/else statement.
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] equals "www.domain.com"}
{
HTTP::respond 301 Location "http://www.domain.com[HTTP::uri]"
}
elseif { [string tolower [HTTP::host]] equals "images.domain.com"}
{
pool images.domain.com
}
else
{
pool public_http_pool
}
} - hoolio
Cirrostratus
The if/elseif/else option will be less efficient than a switch statment--particularly since you're setting the Host header value to lower case again for each conditional check. But yes, that would function.
Aaron - mattboston_5893
Nimbostratus
I'd rather not change our existing rules without having time to test them.
One last question. If I make a request to www.domain.com/images that will be looking for the /images subfolder on the images.domain.com pool, correct? Or can I point /images to the root folder. So if someone requested /images/banners/mybanner.jpg it would look for /banners/mybanner.jpg on the destination pool. - hoolio
Cirrostratus
You can strip /banners from the URI using string range:
HTTP::uri [string range [HTTP::uri] 8 end]
Here's a quick test:
% string range /banners/mybanner.jpg 8 end
/mybanner.jpg
Aaron - mattboston_5893
Nimbostratus
So how would I add the stripping into the following?
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] equals "www.domain.com"}
{
HTTP::respond 301 Location "http://www.domain.com[HTTP::uri]"
}
elseif { [string tolower [HTTP::host]] equals "images.domain.com"}
{
pool images.domain.com
}
elseif { [string tolower [HTTP::host]] starts_with "/images"}
{
pool images.domain.com
}
else
{
pool public_http_pool
}
} - Pconlan_71037
Altocumulus
I would think it needs to be in the scope of the elseif, like this:
elseif { [string tolower [HTTP::uri]] starts_with "/images"}
{
HTTP::uri [string range [HTTP::uri] 7 end]
pool images.domain.com
}
I don't know that it would matter if it was before or after the pool statement since the string inspection has already been done. Note that I changed the string inspection line to use HTTP::uri where you had HTTP::host.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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