Forum Discussion

TJ_Vreugdenhil's avatar
Sep 08, 2011

Redirect iRule from a subdomain to a root domain

users access http://test

Goal: creating a iRule to redirect testsite.com so it will be new.testsite.com

I tried the iRule below but everytime the user makes the request it appends 'testsite.com':


when HTTP_REQUEST { HTTP::redirect "https://www.new.testsite.com/" }
RESULT: "https://www.new.testsite.com/testsite.com/"
----------------------------------
I was thinking the following, thoughts?
HTTP VIP: when HTTP_REQUEST {
HTTP::redirect "https://[HTTP::host][HTTP::uri]"
}
HTTPS VIP: when HTTP_REQUEST {
if { [HTTP::uri] equals "/" } {
HTTP::redirect "https://www.new.testsite.com/" 
}
}
Thanks,
-TJ

3 Replies

  • Ok... got it working:

     

     

    Working iRules

     

     

     

    HTTP VIP iRule:

     

    when HTTP_REQUEST {

     

    HTTP::redirect "https://new.testsite.com[HTTP::uri]"

     

    }

     

     

    HTTPS VIP iRule:

     

    when HTTP_REQUEST {

     

    if { [HTTP::host] equals "test" } {

     

    HTTP::redirect "https://new.testsite.com[HTTP::uri]"

     

    }

     

    }

     

     

     

    Thanks,

     

     

    -TJ

     

  • The second iRule portion will only look for and redirect if the HTTP::host equals "test" specifically.

    You could change the logic so that if it does not equal "new.testsite.com" then it would redirect you to it to cover all known and unknown possibilities.

    Something like:

    
    when HTTP_REQUEST {
    if { !([HTTP::host] equals "new.testsite.com") } {
    HTTP::redirect "https://new.testsite.com[HTTP::uri]"
    }
    }