Forum Discussion

JonasD_46068's avatar
JonasD_46068
Icon for Nimbostratus rankNimbostratus
Mar 15, 2007

REDIRECTION ISSUE

I got the following iRule from someone in this forum:

 

 

when HTTP_REQUEST {

 

set userhost [HTTP::host]

 

if { $userhost == "testdomain.org"} {

 

set userhost "www.[HTTP::host]"

 

}

 

HTTP::redirect https://$userhost[HTTP::uri] }

 

 

It works GREAT. My issue now is I need to be able to add subdomain.testdomain.org, testdomain.net, etc. Creating a 2nd rule doesn't help. I tried combining them and separating them with an 'or' but got errors. I tried downloading the iRule editor but the download link seems to just loop back to where you start. I need this rule because the SSL cert on the F5 is only for www.testdomain.com and the rule prevents the cert error that makes end-user think there's some issue. Please help, I'm an iRule idiot.

 

 

Jhd
  • I tried to use an elseif to add the subdomain.testdomain.com and it is appending www.subdomain.testdomain.com which does NOT exist. So I am close but no cigar. I see 'why' it did it but I"m not sure how to fix. Here's what I tried that didn't quite work:

     

     

    when HTTP_REQUEST {

     

    set userhost [HTTP::host]

     

    if { $userhost == "testdomain.org"} {

     

    set userhost "www.[HTTP::host]"

     

    }

     

    elseif { $userhost == "ml.testdomain.org"} {

     

    set userhost "www.[HTTP::host]"

     

    }

     

    HTTP::redirect https://$userhost[HTTP::uri] }
  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    I think what you're looking for is something like:

    
    when HTTP_REQUEST {
      set userhost [HTTP::host]
      if { $userhost equals "testdomain.org"} {
        set userhost "www.[HTTP::host]"
      } elseif { $userhost equals "ml.testdomain.org"} {
        set userhost "[HTTP::host]"
      } elseif { $userhost equals "testdomain.net"} {
        set userhost "www.[HTTP::host]"
      }
      HTTP::redirect "https://$userhost[HTTP::uri]"
    }

    Note that the way you're manipulating userhost changes depending on what it was set to coming from the client. If you see subdomain.testdomain.org, you're not going to want to prepend a www to it. If you see just testdomain.org or testdomain.net, then you will.

    Make sense?

    Colin
  • Hi Colin,

     

    Here is the detailed issue:

     

    We have HTTP plus HTTPS Virtual-Server, where anyone who will hit:: http://shop.test.com/broutlet or http://shop.test.com/broutlet/* , it should redirect to http://outlet.lenovo.com/broutlet/br/pt/ to be accurate.

     

    Where /* can be anything, for now only http://shop.test.com/broutlet/ redirection is happening to http://outlet.lenovo.com/broutlet/br/pt/ but not with http://shop.test.com/broutlet/*(just one for example : http://shop.test.com/broutlet/br/pt)

     

    Regards PZ

     

  • Hi Team,

     

    The below Irule is working good, sorry for the confusion:

     

    when HTTP_REQUEST {

     

    if { [string tolower [HTTP::uri]] starts_with "/broutlet" } { HTTP::redirect "http://olet.domain.com/broutlet/br/pt/" } }

     

    But this is giving 302 redirection, it should give 301 redirection, how my Irule will look like.

     

    Thanks and Regards Parveez