Forum Discussion

Net_Admin_86160's avatar
Net_Admin_86160
Icon for Nimbostratus rankNimbostratus
Sep 10, 2013

Doing redirects using datagroups

Hello,

 

I am trying to do redirects using datagroups and getting stuck with the actual redirect using -value I have a data group called prod_domains_dg mydomain.ny1.com:=mydomain.ny1.com/1nyb mydomain.ny2.com:=mydomain.ny2.com/2nyb

 

I am trying to do the following

 

  1. if someone enter just https://mydomain.ny1.com then redirect to mydomain.ny1.com/1nyb and send to prod_pool
  2. if somecome comes with a complete link https://mydomain.ny1.com/1nyb/Status.jsp send to a prod_pool.

elseif {[class match [string tolower [HTTP::host]] contains Prod_Domains_dg ]}{ use pool Prod_pool }

 

this works for 2. so the domain groups is accessable and working but for 1 i am not able to replace "/" with {[class match -value [string tolower [HTTP::host]] starts_with Prod_Domains_dg ]

 

Any help in resolving this is appeciated. thanks

 

12 Replies

  • Try this:

    Data group:

    mydomain.ny1.com := /1nyb 
    mydomain.ny2.com := /2nyb
    

    iRule:

    when HTTP_REQUEST { 
        if { [HTTP::uri] equals "/" } {
            if { [class match [string tolower [HTTP::host]] equals Prod_Domains_dg] } {
                HTTP::redirect [class match -value [string tolower [HTTP::host]] equals Prod_Domains_dg]
            }
        }
    }
    

    The pool, I assume, is already applied to the virtual server. So the above only redirects if the URI equals "/" and then redirects to the URI from the class match. Requests with more specific URIs are ignored.

  • check for the target for 1;

     

    e.g.

     

    set target [getfield [HTTP::uri] "/" 2]

     

    then check if target == ""; if true then do the redirect to the new uri.

     

  • Can you post your if statement please. I think your issue will be the fact you are attempting to rewrite the hostname and URI.

     

  • Ahh, I didn't get that you wanted to go to HTTPS. Try this variation:

    when HTTP_REQUEST { 
        if { [HTTP::uri] equals "/" } {
            if { [class match [string tolower [HTTP::host]] equals Prod_Domains_dg] } {
                HTTP::redirect "https://[HTTP::host][class match -value [string tolower [HTTP::host]] equals Prod_Domains_dg]"
            }
        }
    }
    
  • wireshark -

    GET / HTTP/1.1
    
    Host: mydomain.ny1.com
    
    Connection: keep-alive
    
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    
    User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36
    
    Accept-Encoding: gzip,deflate,sdch
    
    Accept-Language: en-US,en;q=0.8
    
    Cookie: avr_2931034823_0_0_4294901760_1679819018_0=1868296818_38074561
    
    
    
    HTTP/1.0 302 Found
    
    Location: https://mydomain.ny1.com/
    
    Server: BigIP
    
    Connection: Keep-Alive
    
    Content-Length: 0
    
  • Well, you're getting redirected, so that's something. Let's add some debug logging:

    when HTTP_REQUEST {
        log local0. "Host equals [HTTP::host]"
        log local0. "Request URI equals [HTTP::uri]"
        if { [HTTP::uri] equals "/" } {
            log local0. "URI equals /"
            if { [class match [string tolower [HTTP::host]] equals Prod_Domains_dg] } {
                log local0. "Matched a data group entry: [class match -value [string tolower [HTTP::host]] equals Prod_Domains_dg]" 
                HTTP::redirect "https://[HTTP::host][class match -value [string tolower [HTTP::host]] equals Prod_Domains_dg]"
            }
        }
    }
    

    Observe this in the LTM log from the management shell:

    tail -f /var/log/ltm
    
  • I suspect, if this still doesn't work, that server side compression is likely causing a problem. Can you disable that for testing?

     

  • Thanks Kevin , and what lies beneath - because I am blind .

    this is working now

    mydomain.ny1.com := /1nyb 
    mydomain.ny2.com := /2nyb
    
    when HTTP_REQUEST {
    if { [class match [string tolower [HTTP::host]] equals Prod_Domains_dg] } {
         if { [HTTP::uri] equals "/" } {
                HTTP::redirect https://[HTTP::host][class match -value [string tolower [HTTP::host]] equals Prod_Domains_dg]
            }
    }
    if { [class match [string tolower [HTTP::host]] equals Staging_Domains_dg] } {
         if { [HTTP::uri] equals "/" } {
                HTTP::redirect https://[HTTP::host][class match -value [string tolower [HTTP::host]] equals Staging_Domains_dg]
            } else {
    use pool stagingWEBFORMS 
    }
    }
    }