Forum Discussion

Matt_59153's avatar
Matt_59153
Icon for Nimbostratus rankNimbostratus
Sep 30, 2008

iRule relocating top level folders to https. Need some help

Hey all,

 

 

Our F5 iRules have been in place for quite some time. We just started digging into them as we are having some issues with folder redirects to secure that it looks like someone found a workaround for by creating iRules for the folders.

 

 

i.e. http://www.blah.com/folder01 has a rule to redirect to http://www.blah.come/folder01/default.aspx

 

 

If the rule doesn't exist the link goes from the folder01 to https://www.blah.com/folder01/

 

 

Here is a sample of the iRules and I am wondering if there is something simple I am missing.

 

 

when HTTP_REQUEST {

 

if { ([HTTP::uri] ends_with "/folder01") and ([HTTP::host] contains "blah.com") } {

 

HTTP::redirect "http://www.blah.com/folder01/default.aspx"

 

} elseif { ([HTTP::uri] ends_with "/folder02") and ([HTTP::host] contains "blah.com") } {

 

HTTP::redirect "http://www.blah.com/folder02/default.aspx"

 

} elseif { ([HTTP::uri] ends_with "/folder03") and ([HTTP::host] contains "blah.com") } {

 

HTTP::redirect "http://www.blah.com/folder03/default.aspx"

 

} elseif { ([HTTP::uri] ends_with "/folder04") and ([HTTP::host] contains "blah.com") } {

 

HTTP::redirect "http://www.blah.com/folder04/default.aspx"

 

} elseif { [matchclass [HTTP::host] equals $::BLAH_Hosts] } {

 

use pool BLAH_WEB

 

} else {

 

HTTP::redirect "http://www.blah.com/default.aspx"

 

}

 

}

 

 

Thanks for the help.

1 Reply

  • How about something like this:

     

     

      
      when HTTP_REQUEST {  
        
          Check if host contains blah.com (case-insensitive)  
         if {[string tolower [HTTP::host]] contains "blah.com"}{  
        
             Redirect based on the requested URI (case-insensitive)  
            switch -glob [string tolower [HTTP::uri]] {  
               "*/folder01" {  
                  HTTP::redirect "http://www.blah.com/folder01/default.aspx"  
        
                   Exit HTTP_REQUEST in this rule  
                  return  
               }  
               "*/folder02" {  
                  HTTP::redirect "http://www.blah.com/folder01/default.aspx"  
        
                   Exit HTTP_REQUEST in this rule  
                  return  
               }  
               "*/folder03" {  
                  HTTP::redirect "http://www.blah.com/folder01/default.aspx"  
        
                   Exit HTTP_REQUEST in this rule  
                  return  
               }  
               "*/folder04" {  
                  HTTP::redirect "http://www.blah.com/folder01/default.aspx"  
        
                   Exit HTTP_REQUEST in this rule  
                  return  
               }  
               default {  
                  HTTP::redirect "http://www.blah.com/default.aspx"  
        
                   Exit HTTP_REQUEST in this rule  
                  return  
               }  
            }  
         } elseif { [matchclass [string tolower [HTTP::host]] equals $::BLAH_Hosts] } {  
            pool BLAH_WEB  
         } else {  
            HTTP::redirect "http://www.blah.com/default.aspx"  
         }  
      }  
      

     

     

    If this doesn't work as you need it to, try adding log statements to track which code paths are running.

     

     

    Aaron