Forum Discussion

dacrud_18985's avatar
dacrud_18985
Icon for Nimbostratus rankNimbostratus
May 20, 2008

redirect help

Hi all,

 

 

So this is the iRule I'm trying to create:

 

 

* redirect anything.domain.com to www.domain.com

 

* if anything.domain.com/us, first make it www.domain.com/us and then direct it to a certain pool

 

* if anything.domain.com/au, first make it www.domain.com/au and then direct it to a certain pool

 

 

I had a response to my post last week on the first step but I can't seem to figure out how to mix it with the last part. Not sure how you can redirect it but yet send it to different pools. Any help would be greatly appreciated.

5 Replies

  • Will this work:

     

     

    when HTTP_REQUEST {

     

    if { [HTTP::host] contains "domain.com"} {

     

    HTTP::redirect http://www[getfield [HTTP::host] ".domain.com" 2][HTTP::uri]

     

    }

     

    if { [HTTP::uri] starts_with "/us" } {

     

    pool pool.name

     

    }

     

    if { [HTTP::uri] starts_with "/au" } {

     

    pool pool.name

     

    }

     

    }
  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    Hi,

    If anything.domain.com and www.domain.com resolve to this VIP, you'll get a redirect loop using HTTP::host contains "domain.com". Here is one approach you could take. I'm sure there alternatives as well.

     
     when HTTP_REQUEST { 
      
         Check if host isn't www.domain.com 
        if {not ([string tolower [HTTP::host]] eq "www.domain.com")}{ 
      
           log local0. "[IP::client_addr]:[TCP::client_port]: redirecting request from [HTTP::host][HTTP::uri] \ 
              to http://www.domain.com[HTTP::uri]" 
      
            Redirect to www.domain.com with the original URI appended 
           HTTP::redirect http://www.domain.com[HTTP::uri] 
      
        } else { 
      
            Select the pool based on the start of the requested path 
           switch -glob [HTTP::path] { 
              "/us*" { 
                  Path started with /us, so use US pool 
         pool US_pool 
                 log local0. "[IP::client_addr]:[TCP::client_port]: using pool US_pool" 
      } 
              "/au*" { 
                  Path started with /au, so use US pool 
                 pool AU_pool 
                 log local0. "[IP::client_addr]:[TCP::client_port]: using pool AU_pool" 
              } 
              default { 
                  Didn't match any of the above cases, so take some default action. 
                 pool default_pool 
                 log local0. "[IP::client_addr]:[TCP::client_port]: using default pool" 
      } 
           } 
        } 
     } 
     

    Aaron
  • Thanks for the help.

     

     

    I'm not seeing how yours would make anything.domain.com/us goto www.domain.com/us to a certain pool. It looks like it will just redirect anything.domain.com/us to http://www.domain.com/us and then skip the "else". Maybe I'm not seeing it.
  • So, for a request for anything.domain.com the iRule will effectively be run twice.

     

     

    The first time a redirect will be sent to the client to go to www.domain.com, keeping the same path.

     

     

    When the client gets the redirect it will request the www.domain.com address.

     

     

    This time when the iRule runs it will hit the else, and direct it to the correct pool.

     

     

    Does that help explain it?