Forum Discussion

hkatzler_36651's avatar
hkatzler_36651
Icon for Nimbostratus rankNimbostratus
Jul 23, 2009

http redirect with using different pools

Hello,

i need an iRule to redirect http requests. I have to use different pools for diffrent redirects.

Sample:

http://keyaccount.company.com should redirect to http://keyaccount.othercompany.net/path/path/index.html and use pool 1 for the redirect.

http://marketing.company.com should redirect to http://marketing.anothercompany.org/path/path/index.html and use pool 2 for the redirect.

 
 when HTTP_REQUEST {  
     if { [HTTP::host] contains "keyaccount.company.com" } {  
         HTTP::redirect "http://keyaccount.othercompany.net/path/path/index.html"  
         This redirect should use pool 1. But how can i do this?     
  
     }   elseif { [HTTP::host] contains "marketing.company.com" } { 
         HTTP::redirect "http://marketing.anothercompany.org/path/path/index.html" 
         This redirect should use pool 2. And so on..... 
   } 
 } 
 

I hope, someone can help me. Thank you for response!

Heiko

5 Replies

  • Hi Heiko,

    I think you want to rewrite the host and/or URI not redirect the client to a new location. Here is an example to get you started:

     
     when HTTP_REQUEST { 
        switch [string tolower [HTTP::host]] { 
      "keyaccount.company.com" { 
               Rewrite / to /path/path/index.html 
              if {[HTTP::path] eq "/"}{ 
                 HTTP::uri "/path/path/index.html" 
              } 
      
               Rewrite host header to keyaccount.othercompany.com 
              HTTP::header replace Host "keyaccount.othercompany.com" 
      
               Use pool1 
              pool pool1 
          } 
      "keyaccount.company.com" { 
               Rewrite / to /path/path/index.html 
              if {[HTTP::path] eq "/"}{ 
                 HTTP::uri "/path/path/index.html" 
              } 
      
               Rewrite host header to keyaccount.othercompany.com 
              HTTP::header replace Host "keyaccount.othercompany.com" 
      
               Use pool1 
              pool pool1 
           } 
           default { 
               Take some default action for other host header values? 
           } 
        } 
     } 
     

    Aaron
  • Hi Aaron,

     

     

    yes, i want redirect the client to another location. The client comes with 'http://keyaccount.company.com' an should redirect to location http://keyaccount.othercompany.net/path/path/index.html. In this case i want to use a special pool for the redirection to the other location.

     

     

    I want to use the same for http://marketing.company.com > http://marketing.anothercompany.org/path/path/index.html with special pool for the redirection to the other location.

     

     

    Similar to URL rewriting with apache reverse proxy function.

     

     

    Heiko
  • Rewriting a URI would mean that LTM changes the requested host and/or URI before sending the request to the pool. The client would not see the change to the request as long as the application doesn't include the rewritten host and/or URI in response headers/content. For HTTP, the term redirecting the client denotes sending a 30x response with the Location header set to the new location. The client would see the change in host and/or URI. If the host was changed in a redirect, the client would resolve the new host value to an IP address and make a new HTTP request to that host.

     

     

    Do you want the client to see the change in host and/or URI? Do the new host values resolve to the same virtual server as the original? The iRule example I posted rewrites the host and URI without redirecting the client. For a more expansive Apache ProxyPass iRule, you can check the Codeshare for two examples (Click here).

     

     

    Aaron
  • Hi Aaron,

     

     

    On top of your discussion, my question is that Is there any catch involved if we redirect from HTTPs to HTTP in the same situation, or the same configuration will do!!!
  • Hi Wum,

     

     

    That example could be used on an HTTP VIP or an HTTPS VIP with a client SSL profile enabled to decrypt the SSL.

     

     

    Aaron