Forum Discussion

TMaCEvans_92750's avatar
TMaCEvans_92750
Icon for Nimbostratus rankNimbostratus
Jul 09, 2010

301-302 redirect problem

currently due to a "quirk" of how a cms i'm using is setup I am left with a site with the following structure

 

www.mydomain.com -goes to pool A

 

www.mydomain.com/UK/ -goes to pool B

 

www.mydomain.com/USA/ -goes to pool C

 

www.mydomain.com/Asia/ -goes to pool D

 

 

also some content is hosted on the root domain

 

 

by default I would like people visiting www.mydomain.com to forward to

 

www.mydomain.com/UK/

 

we a currently doing this by www.mydomain.com send a 302 redirect to www.mydomain.com/UK/

 

 

I would like my f5 to redirect requests to www.mydomain.com to www.mydomain.com/UK/ with a 301

 

but leave requests to www.mydomain.com which are followed by a URI alone

 

redirecting www.mydomain.com requests strait to pool B without touching pool A

 

but still go to pool A if they request a URI other then /UK/,/USA/ or /Asia/

 

 

 

Regards

 

Brett

 

 

1 Reply

  • Hi Brett,

    A switch statement should allow you to do this easily. See the switch wiki page for more info and examples:

    http://devcentral.f5.com/wiki/default.aspx/iRules/switch

    Here is a rough interpretation of what you've described. If it's not exactly what you're looking for, you can test and check the /var/log/ltm file to see what's happening. Once you're done testing, comment out the debug log lines and remove the SERVER_CONNECTED event.

    
    when HTTP_REQUEST {
       log local0. "[IP::client_addr]:[TCP::client_port]: [HTTP::method] to [HTTP::host][HTTP::uri]"
    
        Check the requested URI with wildcard matching
       switch -glob [HTTP::uri] {
          "/" {
              Exact request for /, send 302 to /UK/
             log local0. "[IP::client_addr]:[TCP::client_port]: Redirecting / to /UK/"
     HTTP::redirect "http://www.domain.com/UK/"
          }
          "/UK/*" {
              Request for a URI starting with /UK/
             log local0. "[IP::client_addr]:[TCP::client_port]: Selecting pool_B"
     pool pool_B
          }
          "/USA/*" {
              Request for a URI starting with /USA/
             log local0. "[IP::client_addr]:[TCP::client_port]: Selecting pool_C"
     pool pool_C
          }
          "/Asia/*" {
              Request for a URI starting with /Asia/
             log local0. "[IP::client_addr]:[TCP::client_port]: Selecting pool_D"
     pool pool_D
          }
          default {
              Request for a URI starting with /Asia/
             log local0. "[IP::client_addr]:[TCP::client_port]: Selecting pool_A by default"
     pool pool_A
          }
       }
    }
    when SERVER_CONNECTED {
    
        You can remove this event when done testing
       log local0. "[IP::client_addr]:[TCP::client_port]: selected pool: [LB::server], connected server: [IP::server_addr]:[TCP::server_port]
    }
    

    Aaron