Technical Forum
Ask questions. Discover Answers.
cancel
Showing results for 
Search instead for 
Did you mean: 

iRule /Policy question

Sulabh_Srivasta
Altostratus
Altostratus

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 3

Kevin_Stewart
F5 Employee
F5 Employee

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.

 

Sulabh_Srivasta
Altostratus
Altostratus

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??

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...
      }
   }
}