Forum Discussion

satish_txt_2254's avatar
Nov 01, 2017

iRules base on URL matching

I have following irules and its working but now i have requirement to match URL developers and developer (without "s") so how do i match that string? also i want to redirect developers.vivox.com (both without s) to http to https so i don't know where do i put that rule in following code?

 

when HTTP_REQUEST {
   log local0. "client: [IP::remote_addr] -> [HTTP::host][HTTP::uri]"
   if { [string tolower [HTTP::host]] equals "developers.example.com"}{
      pool DEV_pool
   }
   else {
      pool QA_pool
   }
}

 

3 Replies

  • There are many ways to match redirection things. Easy option to add one more OR condition in same iRule, if statement is same like old irule. Let us know if any question.

     

          when HTTP_REQUEST {
                log local0. "client: [IP::remote_addr] -> [HTTP::host][HTTP::uri]"
                if { ([string tolower [HTTP::host]] equals "developers.example.com") or ([string tolower [HTTP::host]] equals "developer.example.com") }{
                HTTP::redirect "https://[HTTP::host][HTTP::uri]" 
                         }
                 else {
             pool QA_pool
            }
        }
    

     

    • satish_txt_2254's avatar
      satish_txt_2254
      Icon for Cirrus rankCirrus

      as soon as i put following my website stopped working

       

      HTTP::redirect "https://[HTTP::host][HTTP::uri]"

       

      if i type in browser https:// mostly my website works

       

  • A lot depends on how you have your associated virtual servers configured. If you have two virtual servers, one listening for HTTP traffic and the other listening for HTTPS traffic, you could put the redirect iRule only on the HTTP virtual server and this iRule on the HTTPS virtual server. With respect to checking for both "developer.example.com" or "developers.example.com" you can use a single compound IF condition or an IF/ELSEIF structure. For example:

     

    if { [string tolower [HTTP::host]] equals "developers.example.com" || [string tolower [HTTP::host]] equals "developer.example.com" } {
       pool DEV_pool
    } else {
       pool QA_pool
    }