For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

dlegran2_264710's avatar
dlegran2_264710
Icon for Nimbostratus rankNimbostratus
May 27, 2016

Simple redirect irule - keeping VIP name in browser instead of full redirect url

Team ,

 

I am still very new to iRules and I am trying to get the code syntax for a simple URL redirect and Browser check to work based on my requirement. My VIP name is the following http://abc-lab.def.test.com.

 

Basically if I hit url http://abc-lab.def.test.com I get redirected successfully to http://host1.test.com:9500/xyz (shown in my browser).

 

As next step I would like that i still get redirected to http://host1.test.com:9500/xyz url but would like to keep/show in my browser /xyz (ie:http://abc-lab.def.test.com/xyz) or (ie:

 

Here is a snippet of my current code : when HTTP_REQUEST { check for browser-type switch -glob [HTTP::header value "User-Agent"] { "MSIE 6" - "MSIE 7" - "MSIE 8" { If MSIE, log IP, port & browser-type. Logs are written to /var/log/ltm log local0. "[IP::client_addr]:[TCP::client_port] :[HTTP::header User-Agent] : Matched MSIE."

 

             If MSIE, redirect to Capri Redirect page
            HTTP::redirect "http://[HTTP::host]:2200/Redirect_url"  
             }
            default {
             If other browser, log IP, port & browser-type.  Logs are written to /var/log/ltm
            log local0. "[IP::client_addr]:[TCP::client_port] :[HTTP::header User-Agent] : Matched default pool" 

             If other browser, forward to default pool
HTTP::redirect "http://host1.test.com:9500/xyz"
}

} }

 

Any help with this will be greatly appreciated. Remember, I am still new to iRules.

 

Thanks!

 

17 Replies

  • Hi,

    The browser display the request he has done in foreground. To achieve your requirement, you need to :

    or

    • change the way it works :

      when HTTP_REQUEST { 
       check for browser-type 
      switch -glob [HTTP::header value "User-Agent"] { 
          "MSIE 6" - 
          "MSIE 7" - 
          "MSIE 8" { 
               If MSIE, log IP, port & browser-type. Logs are written to /var/log/ltm 
              log local0. "[IP::client_addr]:[TCP::client_port] :[HTTP::header User-Agent] : Matched MSIE."
      
               If MSIE, redirect to Capri Redirect page
              HTTP::redirect "http://[HTTP::host]:2200/Redirect_url"  
          }
          default {
               If other browser, log IP, port & browser-type.  Logs are written to /var/log/ltm
              log local0. "[IP::client_addr]:[TCP::client_port] :[HTTP::header User-Agent] : Matched default pool" 
      
              switch -glob [HTTP::path] {
                  "/" {
                       If other browser, forward to default pool
                      HTTP::redirect "/xyz"
                  }
                  default {
                      node host1 9500
                  }
              }
          }
      } 
      }
      
    • dlegran2_264710's avatar
      dlegran2_264710
      Icon for Nimbostratus rankNimbostratus
      Yann...appreciate fast response based on my example what are the value i should set for node host1 9500
    • Yann_Desmarest_'s avatar
      Yann_Desmarest_
      Icon for Nacreous rankNacreous
      Hi, in that case, your viewable app url remain http://abc-lab.def.test.com. If you redirect the user to http://abc-lab.def.test.com:9500, this is this url that will be viewed in the browser
    • Yann_Desmarest_'s avatar
      Yann_Desmarest_
      Icon for Nacreous rankNacreous
      So, with your irule, the VIP that has this irule never go to a pool but redirect every request to a different app or vip.
  • Hi,

    The browser display the request he has done in foreground. To achieve your requirement, you need to :

    or

    • change the way it works :

      when HTTP_REQUEST { 
       check for browser-type 
      switch -glob [HTTP::header value "User-Agent"] { 
          "MSIE 6" - 
          "MSIE 7" - 
          "MSIE 8" { 
               If MSIE, log IP, port & browser-type. Logs are written to /var/log/ltm 
              log local0. "[IP::client_addr]:[TCP::client_port] :[HTTP::header User-Agent] : Matched MSIE."
      
               If MSIE, redirect to Capri Redirect page
              HTTP::redirect "http://[HTTP::host]:2200/Redirect_url"  
          }
          default {
               If other browser, log IP, port & browser-type.  Logs are written to /var/log/ltm
              log local0. "[IP::client_addr]:[TCP::client_port] :[HTTP::header User-Agent] : Matched default pool" 
      
              switch -glob [HTTP::path] {
                  "/" {
                       If other browser, forward to default pool
                      HTTP::redirect "/xyz"
                  }
                  default {
                      node host1 9500
                  }
              }
          }
      } 
      }
      
    • dlegran2_264710's avatar
      dlegran2_264710
      Icon for Nimbostratus rankNimbostratus
      Yann...appreciate fast response based on my example what are the value i should set for node host1 9500
    • Yann_Desmarest's avatar
      Yann_Desmarest
      Icon for Cirrus rankCirrus
      Hi, in that case, your viewable app url remain http://abc-lab.def.test.com. If you redirect the user to http://abc-lab.def.test.com:9500, this is this url that will be viewed in the browser
    • Yann_Desmarest's avatar
      Yann_Desmarest
      Icon for Cirrus rankCirrus
      So, with your irule, the VIP that has this irule never go to a pool but redirect every request to a different app or vip.
  • Yann..thanks for your suggestion did test it and work correctly now. Last question I now have is how/what to change in order to handle two/three nodes (ie High availability) as for now you suggest to use : default { node host1 9500 which only point to one node. Thanks,