Forum Discussion

dgeorgeson_2230's avatar
dgeorgeson_2230
Icon for Nimbostratus rankNimbostratus
Jul 30, 2011

Replacing the beginning of the URI if entire URI is not explicitly allowed

New to the forum and may have bitten off more than I can chew for a newbie.

 

 

 

I need to create an iRule that meets the following criteria:

 

 

 

if HOST = "www.domain.com" AND URI starts with "/subdirectory" AND the complete URI does not equal either "/subdirectory/checkout.aspx" or "/subdirectory/orderhistory.aspx" THEN URI equals "/newplace" & remaining URI

 

 

 

Essentially if the domain name is true, the URI starts with /subdirectory, and is NOT either of the two specific files listed, then to replace the start of the URI to be /newplace. The intent being to push all traffic into /newplace unless one of two exceptions.

 

 

 

Below is what I have come up with

 

 

 

set STAYURI {"/checkout.aspx" "/orderhistory.aspx"}

 

set CHECKURI {"/subdirectory"}

 

 

 

if { [HTTP::host] equals "www.domain.com" } {

 

if {[string tolower [HTTP::uri]] starts_with CHECKURI } {

 

if {[string tolower [HTTP::uri]] not equals foreach x concat $CHECKURI $STAYURI } {

 

HTTP::uri "/newplace[string range $uri 13 end]"

 

}

 

}

 

 

 

 

am I close to achieving my objective?

 

2 Replies

  • I simplified things a bit which I believe still meets my objective. Since I have a small list of specific URI to not redirect, I rewrote the irule thus

    set STAYURI {"/subdirectory/checkout.aspx" "/subdirectory/orderhistory.aspx"}
    
    if { [HTTP::host] equals "www.domain.com" } {
    if {foreach x $STAYURI {
    [string tolower [HTTP::uri]] not equals x} {
    HTTP::uri "/newplace[string range  $uri 13 end]"
    }
    }
     
  • Hi Dgeorgeson,

     

     

    I think the following untested iRule will be a bit more efficient

     

     

    when HTTP_REQUEST {

     

    set hostn [HTTP::host]

     

    set basen [URI::basename[HTTP::uri]]

     

    set uri [string tolower [HTTP::uri]]

     

    if {($hostn eq "www.domain.com") and ( $uri starts_with "/subdirectory") } {

     

    if { !(($basen eq "checkout.aspx" ) or ($basen eq "orderhistory.aspx")) } {

     

    HTTP::uri "/newplace/$basen"

     

    }

     

    }

     

    }

     

     

    I hope this helps

     

     

    Bhattman