Forum Discussion
iRule to change URI Path
- Jan 30, 2014
There are two problems with your rule. Look at the "first problem" comment which I have added below. This test will catch all requests with the eat9 domain. The subsequent eat9 tests will never execute.
Secondly, you have a misplaced closing bracket. See my "second problem" comment below. This bracket should be moved below the susequent pool statement. The effect of this is that every execution of the rule will attempt to evaluate $last_dir and $last_string, but neither of which have been defined as the definition is in the dead code after my first comment.
Thirdly, I would rewrite the whole thing with a switch statement instead of multiple elseif.
when HTTP_REQUEST { if { [HTTP::host] eq "eat1.blueberry.cheesecakes.com" } { pool PL_eat1.blueberry.cheesecakes.com_1443 } elseif { [HTTP::host] eq "eat2.blueberry.cheesecakes.com" } { pool VSEMPINTWEB07_1444 } elseif { [HTTP::host] eq "eat3.blueberry.cheesecakes.com" } { pool PL_eat3.blueberry.cheesecakes.com_1444 } elseif { [HTTP::host] eq "eat4.blueberry.cheesecakes.com" } { pool PL_eat4.blueberry.cheesecakes.com_1444 } elseif { [HTTP::host] eq "eat5.blueberry.cheesecakes.com" } { log local0.alert "hit for eat5.blueberry.cheesecakes.com -> PL_eat5.blueberry.cheesecakes.com_1444" pool PL_eat5.blueberry.cheesecakes.com_1444 } elseif { [HTTP::host] eq "eat7.blueberry.cheesecakes.com" } { pool PL_eat7.blueberry.cheesecakes.com_1444 } elseif { [HTTP::host] eq "eat8.blueberry.cheesecakes.com" } { pool PL_eat8.blueberry.cheesecakes.com_1444 } elseif { [HTTP::host] eq "eat9.blueberry.cheesecakes.com" } { first problem pool PL_eat9.blueberry.cheesecakes.com_1444 } elseif { ([HTTP::host] eq "eat9.raspberry.cheesecakes.com") && ([HTTP::uri] starts_with "/foneat") } { pool PL_eat9.blueberry.cheesecakes.com_1444 } elseif { ([HTTP::host] eq "eat9.raspberry.cheesecakes.com") && ([HTTP::uri] starts_with "/css") } { pool PL_eat9.blueberry.cheesecakes.com_1444 } elseif { ([HTTP::host] eq "eat9.raspberry.cheesecakes.com") && ([HTTP::uri] starts_with "/templates") } { pool PL_eat9.blueberry.cheesecakes.com_1444 } elseif { ([HTTP::host] eq "eat9.raspberry.cheesecakes.com") && ([HTTP::uri] starts_with "/js") } { pool PL_eat9.blueberry.cheesecakes.com_1444 } elseif { ([HTTP::host] eq "eat9.raspberry.cheesecakes.com") && ([HTTP::uri] starts_with "/images") } { pool PL_eat9.blueberry.cheesecakes.com_1444 } elseif { ([HTTP::host] eq "eat9.raspberry.cheesecakes.com") && ([HTTP::uri] starts_with "/cache/*") } { Get the index of the last URI directory set depth [URI::path [HTTP::uri] depth] Parse the last directory in the path set last_dir [URI::path [HTTP::uri] $depth $depth] Parse everything after the last directory set last_string [string trimleft [string range string $last_dir end]] } second problem { HTTP::redirect "[HTTP::host]/$last_dir$last_string" } { pool PL_eat9.blueberry.cheesecakes.com_1444 } }
There are two problems with your rule. Look at the "first problem" comment which I have added below. This test will catch all requests with the eat9 domain. The subsequent eat9 tests will never execute.
Secondly, you have a misplaced closing bracket. See my "second problem" comment below. This bracket should be moved below the susequent pool statement. The effect of this is that every execution of the rule will attempt to evaluate $last_dir and $last_string, but neither of which have been defined as the definition is in the dead code after my first comment.
Thirdly, I would rewrite the whole thing with a switch statement instead of multiple elseif.
when HTTP_REQUEST {
if { [HTTP::host] eq "eat1.blueberry.cheesecakes.com" } {
pool PL_eat1.blueberry.cheesecakes.com_1443
} elseif { [HTTP::host] eq "eat2.blueberry.cheesecakes.com" } {
pool VSEMPINTWEB07_1444
} elseif { [HTTP::host] eq "eat3.blueberry.cheesecakes.com" } {
pool PL_eat3.blueberry.cheesecakes.com_1444
} elseif { [HTTP::host] eq "eat4.blueberry.cheesecakes.com" } {
pool PL_eat4.blueberry.cheesecakes.com_1444
} elseif { [HTTP::host] eq "eat5.blueberry.cheesecakes.com" } {
log local0.alert "hit for eat5.blueberry.cheesecakes.com -> PL_eat5.blueberry.cheesecakes.com_1444"
pool PL_eat5.blueberry.cheesecakes.com_1444
} elseif { [HTTP::host] eq "eat7.blueberry.cheesecakes.com" } {
pool PL_eat7.blueberry.cheesecakes.com_1444
} elseif { [HTTP::host] eq "eat8.blueberry.cheesecakes.com" } {
pool PL_eat8.blueberry.cheesecakes.com_1444
} elseif { [HTTP::host] eq "eat9.blueberry.cheesecakes.com" } { first problem
pool PL_eat9.blueberry.cheesecakes.com_1444
} elseif { ([HTTP::host] eq "eat9.raspberry.cheesecakes.com") && ([HTTP::uri] starts_with "/foneat") } {
pool PL_eat9.blueberry.cheesecakes.com_1444
} elseif { ([HTTP::host] eq "eat9.raspberry.cheesecakes.com") && ([HTTP::uri] starts_with "/css") } {
pool PL_eat9.blueberry.cheesecakes.com_1444
} elseif { ([HTTP::host] eq "eat9.raspberry.cheesecakes.com") && ([HTTP::uri] starts_with "/templates") } {
pool PL_eat9.blueberry.cheesecakes.com_1444
} elseif { ([HTTP::host] eq "eat9.raspberry.cheesecakes.com") && ([HTTP::uri] starts_with "/js") } {
pool PL_eat9.blueberry.cheesecakes.com_1444
} elseif { ([HTTP::host] eq "eat9.raspberry.cheesecakes.com") && ([HTTP::uri] starts_with "/images") } {
pool PL_eat9.blueberry.cheesecakes.com_1444
} elseif { ([HTTP::host] eq "eat9.raspberry.cheesecakes.com") && ([HTTP::uri] starts_with "/cache/*") } {
Get the index of the last URI directory
set depth [URI::path [HTTP::uri] depth]
Parse the last directory in the path
set last_dir [URI::path [HTTP::uri] $depth $depth]
Parse everything after the last directory
set last_string [string trimleft [string range string $last_dir end]]
} second problem
{ HTTP::redirect "[HTTP::host]/$last_dir$last_string" }
{ pool PL_eat9.blueberry.cheesecakes.com_1444 }
}
- uniJan 30, 2014AltostratusLastly, please use the Preformatted Code button when pasting code. It is a real pain reading otherwise, and people are less likely to bother trying to read your code.
- Oxenburger_1420Jan 31, 2014NimbostratusHi, I've worked how to strip the first two directories of the URI and parse the remaining subdirectories + basename + query string, which are then used to change the URI Path. I've posted the info here - link text Unfortunately couldn't get switch -glob to work but will keep trying. using elsif for now. Thanks, Dave
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