Forum Discussion

Oxenburger_1420's avatar
Oxenburger_1420
Icon for Nimbostratus rankNimbostratus
Jan 30, 2014
Solved

iRule to change URI Path

Hi, I'm trying to create an iRule that matches URI starting with “eat9.raspberry.cheesecake.com/cache//()” to resolves to “eat9.raspberry.cheesecake.com/(*)” via the F5 i.e. “eat9.raspberry.chees...
  • uni_87886's avatar
    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 } 
    }