Forum Discussion

Sulabh_Srivasta's avatar
Sulabh_Srivasta
Icon for Altostratus rankAltostratus
Nov 02, 2022

iRule /Policy question

Hello everyone,

Please assist me with iRule ,  I have a scenario where I have to redirect the URL as well as forward traffic to different pools for example:

when users hit - www.abc.com/xxxx it should redirect to www.abc.com/xxx/web/home/index.html and forward traffic to pool A,  when users hit - www.abc.com/yyyy it should redirect to www.abc.com/yyyy/forms/index.html and forward traffic to pool B

Thank you

 

 

 

3 Replies

  • There's a few ways to skin this depending on what you mean by "redirect". Generally when you say "redirect" with respect to HTTP traffic, you mean issuing a 30x redirect response to the user. Otherwise, you might simply mean silently changing the URI path as it flows through the proxy. The former is seen and handled by the client, whereas the latter the client doesn't see.

    But I'll assume for this instance, and because it's usually better form, that you mean an actual 30x redirect.

    when HTTP_REQUEST {
        switch -glob [string tolower [HTTP::uri]] {
            "/xxxx" {
                HTTP::redirect "https://[HTTP::host]/xxxx/web/home/index.html"
            }
            "/yyyy" {
                HTTP::redirect "https://[HTTP::host]/yyyy/forms/index.html"
            }
            "/xxxx*" {
                pool pool_A
            }
            "/yyyy*" {
                pool pool_B
            }
        }
    }

    The above basically says, if the URI is /xxxx or /yyyy, perform a 30x redirect to the correct URI path. If the URI starts with /xxxx or /yyyy (contains more than just that string), then send to a pool.

     

  • Thanks Kevin, It worked, now I have another requiremen, the rediretion based on http method.  

    How to configure an HTTP virtual server to redirect based on http method??

    • Kevin_Stewart's avatar
      Kevin_Stewart
      Icon for Employee rankEmployee

      Use the HTTP::method condition:

      when HTTP_REQUEST {
         if { [HTTP::method] eq "POST" } {
            HTTP::redirect...
         }
      }

      or

      when HTTP_REQUEST {
         switch [HTTP::method] {
            "POST" {
               HTTP::redirect...
            }
            "GET" {
               HTTP::redirect...
            }
            "UPDATE" {
               HTTP::redirect...
            }
            default {
               HTTP::redirect...
            }
         }
      }