Forum Discussion

amritkp789's avatar
amritkp789
Icon for Nimbostratus rankNimbostratus
Sep 06, 2018

Need some help with iRule for URI redirection.

I have an irule that uses a string-data-group to list the old URIs and new URIs to which it should be redirected to. Here are the details:

 

ltm data-group internal redir_dgl { records { / { data https://abcnew.example.com } /abcold/uri1 { data https://abcnew.example.com/uri1 } /abcold/uri2 { data https://abcnew.example.com/uri2 } /abcold/uri1/uri3 { data https://abcnew.example.com/uri1 } } type string }

 

when HTTP_REQUEST { set REDIRECT [class match -value [string tolower [HTTP:uri]]equal redir_dgl] if { $REDIRECT ne "" } { HTTP::respond 301 Location "$REDIRECT" } else { pool $POOL_DEFAULT } }

 

This is just a sample. Now in this setup I observe that few redirection do not take effect, and rather I get 404 error. What can be the possible issue?

 

  • Might I suggest you insert some logging:

    when HTTP_REQUEST { 
        set REDIRECT [class match -value [string tolower [HTTP:uri]]equal redir_dgl] 
        log local0. "REDIRECT = $REDIRECT"
        if { $REDIRECT ne "" } { 
            log local0. "redirecting to $REDIRECT"
            HTTP::respond 301 Location "$REDIRECT" 
        } else { 
            log local0. "sending to default pool"
            pool $POOL_DEFAULT 
        } 
    }
    

    You may be surprised by some of the URLs your getting.