Forum Discussion

Aaron_Magruder_'s avatar
Aaron_Magruder_
Icon for Nimbostratus rankNimbostratus
Mar 30, 2005

Removing / inserted by iRule variable

Is there a way to prevent the / from being inserted when using variables? The following iRule works to redirect users from /29900 to /Templates/IQuote010.cfm?ID=/29900. I need a way to remove the / between ID=/29900 so the uri looks like /Templates/IQuote010.cfm?ID=29900.

/29900 (initial uri)

/Templates/IQuote010.cfm?ID=29900 (uri should look like this)

/Templates/IQuote010.cfm?ID=/29900 (need to remove the /)

   
 when HTTP_REQUEST {  
    set uri [HTTP::uri] 
    set host [HTTP::host] 
    set new_uri /Templates/IQuote010.cfm?ID= 
    set new_url $host$new_uri$uri 
    if { [HTTP::uri] starts_with "/Templates"  } { 
       use pool UITShared-172-29-98-77 
    } 
    else { 
       HTTP::redirect http://$new_url 
    } 
 } 
 

6 Replies

  • unRuleY_95363's avatar
    unRuleY_95363
    Historic F5 Account
    Try changing the "set uri" line to:

     
     set uri [string trimleft [HTTP::uri] "/"] 
     

  • Thanks. This worked like a champ. I think there is a better way to accomplish this but I'm not sure how. The current way I have configured it, I will need to include any new directories in the rule. We would like to look for 5 digits in the uri. If there are only 5, then we would like to redirect to /Templates/.... Everything else would use the pool. This would prevent use from having to add new directories to the rule.

     

     

    If you have any ideas, let me know.

     

     

    when HTTP_REQUEST {

     

    set uri [string trimleft [HTTP::uri] "/"]

     

    set host [HTTP::host]

     

    set new_uri /Templates/IQuote010.cfm?ID=

     

    set new_url $host$new_uri$uri

     

    if { [HTTP::uri] starts_with "/Templates" or [HTTP::uri] starts_with "/images" } {

     

    use pool UITShared-172-29-98-77

     

    }

     

    else {

     

    HTTP::redirect http://$new_url

     

    }

     

    }
  • Would this work? Sorry, I don't have a pair with which to test right now, F5 pried our evaluation units out of our hands last Friday. Hopefully a PO will be cut soon.

     

     

    when HTTP_REQUEST {

     

    set uri { string trimleft [http::uri] "/" }

     

    set uri_length { string length $uri }

     

    set host [HTTP::host]

     

    set new_uri /Templates/IQuote010.cfm?ID=

     

    set new_url $host$new_uri$uri

     

    if { $uri_length = 5 } {

     

    HTTP::redirect http://$new_url

     

    log "Redirecting [IP::client_addr] to http://$new_url"

     

    }

     

    else {

     

    use pool UITShared-172-29-98-77

     

    }

     

    }
  • I think that can be chopped down:

     

     

    when HTTP_REQUEST {

     

    set uri { string trimleft [http::uri] "/" }

     

    set url [HTTP::host]/Templates/IQuote010.cfm?ID=

     

    if { string length $uri = 5 } {

     

    HTTP::redirect http://$url$uri

     

    log "Redirecting [IP::client_addr] to http://$url$uri"

     

    }

     

    else {

     

    use pool UITShared-172-29-98-77

     

    }

     

    }

     

     

  • Neither of those options worked. The LTM didn't send the redirect.

     

     

    when HTTP_REQUEST {

     

    set uri { string trimleft [http::uri] "/" }

     

    set uri_length { string length [http::uri] }

     

    set host [HTTP::host]

     

    set new_uri /Templates/IQuote010.cfm?ID=

     

    set new_url $host$new_uri$uri

     

    if { [string length http::uri] equals 5 } {

     

    HTTP::redirect http://$new_url

     

    }

     

    else {

     

    use pool UITShared-172-29-98-77

     

    }

     

    }
  • In this line:

     

     

    if { [string length http::uri] equals 5 }

     

     

    The unformatted uri still has the / in it, are you including that in the 5 characters, or should it be 6 with the /. Otherwise, you could use the $uri variable. Add some logging for debugging purposes that shows you the output of the string manipulations, such as

     

     

    set uri_length { string length [HTTP::uri] }

     

    set uri__formatted_length { string length $uri }

     

    log " URI is [HTTP::uri] "

     

    log " URI formatted is $uri "

     

    log " URI lenght is $uri_length "

     

    log " URI formatted length is $uri_formatted_length "