Forum Discussion

ibrahim_37929's avatar
Icon for Nimbostratus rankNimbostratus
Aug 16, 2016

delete port i rule with specific address

Hi i use an i rule for deleting ports on application servers. But the problem is when i called the ip address:port of an application server i rule deletes the ports of application server. So i want to write an exception for the specific ip address. here is my i rule:

if {[HTTP::header exists "Location"]}{
    set org_location [HTTP::header "Location"]
    set http_part [substr $org_location 0 "//"]
    if {$http_part eq "http:"}{
        set remain_part [findstr $org_location $http_part 5]
    elseif {$http_part eq "https:"}{
        set remain_part [findstr $org_location $http_part 6]
    set port_str [findstr $remain_part ":"]
    set port_num [substr $port_str 1 4]
         deletes the ports between 9080 and 9199 

    if {($port_num >= 9080) and ($port_num <= 9199)}
            set the_port [substr $port_str 0 5]
            set part1 [substr $org_location 0 $the_port]
            set part2 [findstr $org_location $the_port 5]
            if {$org_location contains $the_port}{
            set org_location "$part1$part2"
            HTTP::header replace Location $org_location}        

I want to modify this irule so; if the url contains the ip address, i rule wouldn't delete the ports.

Thanks for your help

1 Reply

  • Hi Ibrahim,

    you may take a look to the iRule below. It used a less complex syntax using the

    commands to parse the original
    header to decide if a rewrite is needed. But also uses a
    [string match]
    command to identify IPs within the host values.

    when HTTP_RESPONSE {
        if { [set http_location [HTTP::header value "Location"]] ne "" } then {
            if { ( [set uri_port [URI::port $http_location]] >= 9080 ) and 
                 ( $uri_port <= 9199 ) and not 
                 ( [string match {[0-9]*.[0-9]*.[0-9]*.[0-9]*} [URI::host $http_location]] ) } then {
                HTTP::header replace Location "[substr $http_location 0 ":$uri_port"][findstr $http_location ":$uri_port" 5]"

    Cheers, Kai