Forum Discussion

Peak_10_71174's avatar
Peak_10_71174
Icon for Nimbostratus rankNimbostratus
Dec 02, 2009

irule redirect verification

I have the need to add an irule that will redirect various https requests to a different url. Since I'm not very familiar with all the rules regarding syntax and order of these various requests, what I am wondering is if I need to put the least specific redirects last in the sequence, or if it matters.

 

 

For example, I need the following redirects:

 

 

1. companytest.abc.com/path1 to companypath1.abc.com/test

 

2. companytest.abc.com/path2 to companypath2.abc.com/test

 

3. companytest.abc.com to company.abc.com/test

 

 

Here is the sample irule I have create in order to do this, I was wondering if someone could verify that I have placed these in the correct order to account for no.3 being the least specific of all the redirects:

 

 

when HTTP_REQUEST {

 

 

if { [string tolower [HTTP::host]] eq "companytest.abc.com" && [HTTP::uri] eq "/path1" } {

 

 

HTTP::redirect "companypath1.abc.com/test"

 

 

if { [string tolower [HTTP::host]] eq "companytest.abc.com" && [HTTP::uri] eq "/path2" } {

 

 

HTTP::redirect "companypath2.abc.com/test"

 

 

if { [string tolower [HTTP::host]] eq "companytest.abc.com"} {

 

 

HTTP::redirect "http://company.abc.com/test"

 

 

}

 

 

}

 

 

Let me know if you need more clarification. Thanks for any help in advance.

1 Reply

  • You could use a switch statement or two to do this. It should save you a few evaluations of [string tolower [HTTP::host]].

    I'm not sure if you want to do an exact check or a wildcard check of the URI to see if they start with /path1 or /path2. This example does a wildcard check. If you want exact matching, remove the -glob flag from the switch statement and the *'s from the switch cases.

    1. companytest.abc.com/path1 to companypath1.abc.com/test

    2. companytest.abc.com/path2 to companypath2.abc.com/test

    3. companytest.abc.com to company.abc.com/test

     
     when HTTP_REQUEST { 
      
         Check the requested host 
        switch [string tolower [HTTP::host]] { 
      
           "companytest.abc.com" { 
      
               Check requested URI 
      switch -glob [HTTP::path] { 
         "/path1*" { 
            HTTP::redirect "http://companypath1.abc.com/test" 
         } 
         "/path1*" { 
            HTTP::redirect "http://companypath2.abc.com/test" 
         } 
         "/" { 
            HTTP::redirect "http://company.abc.com/test" 
         } 
         default { 
             Take some default action? 
         } 
      } 
           } 
           default { 
               Will other host header values be used in requests to the VIP 
        If so, take some default action? 
           } 
        } 
     } 
     

    Aaron