Forum Discussion

Joe_Pipitone's avatar
Joe_Pipitone
Icon for Nimbostratus rankNimbostratus
Jun 02, 2010

Unique redirect iRule help

We have an iRule that doesn't seem to be doing the job, and just ends up in a redirect loop. I'm pretty sure why, however I am not 100% sure how to get this working properly. We have a website, lets say its http://events.oursite.com. When a user visits the homepage of this site, we want to redirect them to http://anothersite.com/events. when a user goes to http://events.oursite.com/somedir/somepage.aspx, we want them to stay there, no redirection. When I put the following iRule in place, a loop occurs. I am thinking this is happening because if they go to the homepage, the iRule is catching and redirecting them multiple times to http://events.oursite.com over and over again. What am I missing here? Any help is appreciated.

when HTTP_REQUEST { 
    if { ([HTTP::host] eq "events.oursite.com") } { 
        switch -glob [HTTP::uri] { 
             "/" { HTTP::redirect "http://anothersite.com/events" } 
             default {  HTTP::redirect "http://events.oursite.com[HTTP::uri]" }
        } 
    } 
}

1 Reply

  • I figured this one out on my own, I had to use a default statement inside an if statement
    if {[HTTP::uri] eq "/" } {
            switch -glob [HTTP::uri] { 
                 "/" { HTTP::redirect "http://anothersite.com/events" } 
                 default {  HTTP::redirect "http://events.oursite.com[HTTP::uri]" }
            } 
          }