Forum Discussion

Angelina_Van_Ry's avatar
Angelina_Van_Ry
Icon for Nimbostratus rankNimbostratus
Jul 17, 2017

HTTP redirect iRule overriding all other subdirectories

Hello all,

I am attempting to have anything that goes to contoso.com/folder contoso.com/other to go to their respective pools but I would like to have requests going to contoso.com go to . I have an iRule setup so that when anything goes to the traffic gets redirected to . However, the minute I use the HTTP::redirect command, it apprears to completely override the iRules for my subfolders and every request, including and , gets redirected to . Is there some logic or prioritization I am missing here? Currently, all three iRules live on the same virtual server and they are as follows:

iRule 1:

when HTTP_REQUEST {
  Access to www.contoso.com/folder
  
   if { [string tolower [HTTP::host]] equals "www.contoso.com"} {
  
    Access to sub-folder
 
     if { [string tolower [HTTP::uri]] starts_with "/folder" } {

         pool Contoso_Folder_Pool
      }
    }
}

iRule 2:

when HTTP_REQUEST {

  Access to www.contoso.com/other
   if { [string tolower [HTTP::host]] equals "www.contoso.com"} {
  
    Access to sub-folder
 
     if { [string tolower [HTTP::uri]] starts_with "/other" } {

         pool Contoso_Other_Pool
      }
    }
}

iRule 3:

when HTTP_REQUEST {

 if {[string tolower [HTTP::host]] equals "www.contoso.com" } {

     HTTP::redirect "https://www.newwebsite.com"

   }

}
  • Heya,

    Could you combine the three rules into something like the following?

    when HTTP_REQUEST {
    if { [string tolower [HTTP::host]] equals "www.contoso.com" } {
        if { [string tolower [HTTP::uri]] starts_with "/folder" } {
            pool Contoso_Folder_Pool
        } elseif { [string tolower [HTTP::uri]] starts_with "/other" } {
            pool Contoso_Other_Pool
        } else {
            HTTP::redirect "https://www.newwebsite.com"
        }
    }
    }