Forum Discussion
A_tech_85188
Nimbostratus
May 01, 2008Pool Redirect
Hello All,
I need to setup an irule, but am newbie to irule's.
I need it to do this.
When someone puts in www.samplesite.com/sample1
it directs them to the sample1 pool.
I need the sample1 to remain at the end of the url like this: www.samplesite.com/sample1.
Can someone point me to an existing irule sample that does this or point me in the right direction to get started with this?
Thanks
6 Replies
- A_tech_85188
Nimbostratus
Thanks for your reply Hoolio,
Looks like this will almost work for us, However we need it to parse the entire character set after the slash instead of just the first letter.
This is the line I believe needs to be modified:
Parse first character after the leading slash
set pool_string [string toupper [string range [HTTP::path] 1 1]]
I am not sure what needs to be changed? Can you point me in the right direction on this?
I posted the entire irule below.
Thanks
Parse the URI to determine which pool to send requests to.
The pool string should be the second character in the URI.
Example: The pool for URI '/A/path/to/file.ext' is pool_A
Change "default_pool" to the pool which should be used if the parsed pool name doesn't exist.
when HTTP_REQUEST {
Check if requested path is at least two characters long
if {[string length [HTTP::path]] > 1}{
Parse first character after the leading slash
set pool_string [string toupper [string range [HTTP::path] 1 1]]
Try to set the pool based on the URI. If the pool name doesn't exist, catch the error.
if { [catch {pool pool_${pool_string}}]}{
The pool parsed from the URI didn't exist
log local0. "Error assigning pool to pool_${pool_string}"
Assign a default pool for this request
pool default_pool
}
}
} - hoolio
Cirrostratus
That looks about right. Is the portion of the URI always the same length? ie, are your pool names pool_SAMPLE1, pool_SAMPLE2, etc? If so, you can change the command to:
set pool_string [string toupper [string range [HTTP::path] 1 7]]
You can test the string range command using a simplified test rule:when RULE_INIT { Save a test path set ::path "/sample1/path/to/file.ext" Starting with the / as positiion 0, parse the path set ::pool_string [string toupper [string range $::path 1 7]] log local0. "\$::pool_string: $::pool_string" }
Here is the sample output from /var/log/ltm:
Rule : $::pool_string: SAMPLE1
Once you get that working, you can use the same command in the normal iRule. Just replace the test variable $::path with [HTTP::path].
set pool_string [string toupper [string range [HTTP::path] 1 7]]
Aaron - A_tech_85188
Nimbostratus
Hi,
No the portion of the URI will not always the same length. It could be pool_SAMPLE1, pool_NEWSAMPLE2, or pool_THISISANEWSAMPLE2.
Basically I am trying to get it to match whatever is typed after the slash at the end of the URI. We will make sure we name the pool the same as the subdomain (www.samplesite.com/sample1) a user will be typing in.
So will this set pool_string [string toupper [string range [HTTP::path] 1 7]] match the characters after the slash with the pool name? I am guessing that I would need to set the string range very hi to make sure it will catch all the characters and match them up?
Thanks for all your help on this. - hoolio
Cirrostratus
If you want to get the whole path minus the leading slash, you could either use 'string range [HTTP::path] 1 end', or 'string trimleft [HTTP::path] "/"'.
So all requests to the VIP will only have a path equal to the pool name? Would a client ever request www.example.com/sample1/file.jpg for example? If so, the rule would try to assign a pool of pool_SAMPLE/FILE.JPG. Do you want to get the first part of the URI between the first forward slash and the second? To do that, you could use getfield (Click here):
getfield [HTTP::path] "/" 1
Aaron - A_tech_85188
Nimbostratus
Hi Aaron,
Thanks for that. I don't think I will need to use the getfield as we plan to send them to a default pool page that says something like "This site does not exist" I made some changes to the irule (See below). I wanted to run it by you before turning it up live on our Big IP. Does everything look correct to you?
Parse the URI to determine which pool to send requests to.
The pool string should match all the characters in the URI after the leading slash.
Example: The pool for URI '/ABC/' is pool_ABC
Change "default_pool" to the pool which should be used if the parsed pool name doesn't exist.
when HTTP_REQUEST {
Check if requested path is at least two characters long
if {[string length [HTTP::path]] > 1}{
Get the whole path minus the leading slash
set pool_string [string toupper [string range [HTTP::path] 1 end]
Try to set the pool based on the URI. If the pool name doesn't exist, catch the error.
if { [catch {pool pool_${pool_string}}]}{
The pool parsed from the URI didn't exist
log local0. "Error assigning pool to pool_${pool_string}"
Assign a default pool for this request
pool default_pool
}
}
}
Again thanks for all your help! - hoolio
Cirrostratus
The syntax looks good. I'm still not 100% sure about the logic for the URIs though. In typical applications, every request wouldn't be to a single path, so the idea of assigning a pool based on the path wouldn't work. I suppose it's possible if the content for the app is generated based just off of the parameters and parameter values.
Anyhow, the syntax looks okay. If you want to be more sure about the functionality, you could test it on another BIG-IP or by creating a test VIP on the production BIG-IP.
Aaron
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