Forum Discussion

gauravarora_370's avatar
gauravarora_370
Icon for Nimbostratus rankNimbostratus
Aug 29, 2018

one rewrite url works and another does not.

Hello

 

I have written an iRule script to rewrite a url based on a condition-

 

http://intfilings.abc.gov/navigator_icm/?desktop=xyz should rewrite to

 

http://intfilings.abc.gov/EFilingWeb/ManageTicklers should rewrite to

 

Here is the iRule script- When HTTP_REQUEST { if { [HTTP::header host] equals "intfilings.abc.gov" && [HTTP::header uri] starts_with "/navigator_icm" } { HTTP::header replace Host "server1.ct.gov:9081" } if { [HTTP::header host] equals "intfilings.abc.gov" && [HTTP::header uri] starts_with "/EFilingWeb" } { HTTP::header replace Host "server2.ct.gov:9080" }

 

}

 

Whichever URL i click on first works and then the other does not.

 

3 Replies

  • You have an error in your code, [HTTP::header uri] will look for a header called 'uri', whereas I assume you mean HTTP::uri.

    You are also checking for the same header twice so I've put it in one 'if' statement as well as adding a couple of lines of logging that may help troubleshooting. You also may want to consider using string tolower if this is accessed via a browser as URI is case sensitive. Please try the following.

     

    when HTTP_REQUEST { 
        if {[HTTP::header "Host"] equals "intfilings.abc.gov"} {
            if {[HTTP::uri] starts_with "/navigator_icm"} {
                log local0. "replacing host on URI: [HTTP::uri]"
                HTTP::header replace Host "server1.ct.gov" 
            } elseif {[HTTP::uri] starts_with "/EFilingWeb"} {
                log local0. "replacing host on URI: [HTTP::uri]"
                HTTP::header replace Host "server2.ct.gov"
            }
        }
    }
    

     

    You can also perform the same functionality using LTM Traffic Policies, these are recommended for simple iRules such as these.

  • Hi,

    can you try this (I dont' think it's necessary to add port in host header...):

     

    When HTTP_REQUEST {
    
    if { [HTTP::host] equals "intfilings.abc.gov" && [HTTP::uri] starts_with "/navigator_icm" } {
        HTTP::header replace Host "server1.ct.gov:9081"
     }
    
     if { [HTTP::host] equals "intfilings.abc.gov" && [HTTP::uri] starts_with "/EFilingWeb" } {
        HTTP::header replace Host "server2.ct.gov:9080"
     }
    
    }
    

     

    So can you try with port in host header an without please

  • try this for logging (irule from Lee with logging request not matching any of 2 conditions)

     

    when HTTP_REQUEST { 
        if {[HTTP::host] equals "intfilings.abc.gov"} {
            if {[HTTP::uri] starts_with "/navigator_icm"} {
                log local0. "replacing host header with : server1.ct.gov on URI: [HTTP::uri]"
                HTTP::header replace Host "server1.ct.gov" 
            } elseif {[HTTP::uri] starts_with "/EFilingWeb"} {
                log local0. "replacing host header with : server2.ct.gov on URI: [HTTP::uri]"
                HTTP::header replace Host "server2.ct.gov"
            } else {
                log local0. "Unchanged host header on URI: [HTTP::uri]"
            }
        }
    }