Forum Discussion

Robert_47833's avatar
Robert_47833
Icon for Altostratus rankAltostratus
Sep 26, 2011

Hi,how to set domain in this situation

Dear irule

 

in one irule,there are 2 types request

 

https://1.cjj.com/aaaa

 

https://1.cjj.co.uk/aaaa

 

 

 

I want to redirect them to my.1.cjj.com or .co.uk

 

elseif {$uri starts_with "/aaaa"} {

 

if { [HTTP::host] ends_with ".co.uk"} {

 

HTTP::redirect https://my.1.cjj.co.uk

 

}

 

 

elseif {[HTTP::host] ends_with ".com"} {

 

HTTP::redirect https://my.1.cjj.com

 

}

 

 

 

my question is :

 

because there are 4 other places in this irule need use redirect this types uri

 

 

should I configure something like this to avoid use if /elseif in each condition

 

set domain [domain [HTTP::host] 2]

 

 

but in order to handle 1.cjj.com and 1.cjj.co.uk together ,how to achieve this?

 

 

if {HTTP::host] ends_with ".co.uk} {

 

 

set domain [domain [HTTP::host] 3]

 

}

 

elseif {HTTP::host] ends_with ".com} {

 

set domain [domain [HTTP::host] 2]

 

}

 

 

is this one right?

 

do u have someone who is better than mine,pls show me

 

Thanks in advance
  • Hi jucao,

    I would suggest not using the domain command in this situation since you have one two different levels that you are looking for. I think in this situation just using the ends_with comparison would be more efficient.

    Let me know if this works for you.

     
    when HTTP_REQUEST {
    switch -glob [string tolower [HTTP::uri]] {
    "/aaaa*" {
    if { [HTTP::host] ends_with ".co.uk" } {
    HTTP::redirect "https://my.1.cjj.co.uk"
    }
    elseif { [HTTP::host] ends_with ".com" } {
    HTTP::redirect "https://my.1.cjj.com"
    }
    }
    "/bbbb*" { HTTP::redirect "http://www.google.com" }
    "/cccc*" { HTTP::redirect "http://www.yahoo.com" }
    }
    }
    
  • hmmm,thanks,Michael

     

    because there are some seperated parts in irule need redirect

     

    so I want to put this co.uk and com in one variable

     

    https://1.cjj.com/aaaa

     

    https://1.cjj.co.uk/aaaa

     

     

    for example domain variable cache .com or .co.uk

     

    so I just need to use

     

    switch -glob [string tolower [HTTP::uri]] {

     

    "/aaaa*" {

     

    HTTP::redirect "https://my.1.cjj$domain"

     

    }

     

    is it ok?

     

    how to use a effeicent way to cache this .com and .co.uk
  • hmmm,thanks,Michael

     

    because there are some seperated parts in irule need redirect

     

    so I want to put this co.uk and com in one variable

     

    https://1.cjj.com/aaaa

     

    https://1.cjj.co.uk/aaaa

     

     

    for example domain variable cache .com or .co.uk

     

    so I just need to use

     

    switch -glob [string tolower [HTTP::uri]] {

     

    "/aaaa*" {

     

    HTTP::redirect "https://my.1.cjj$domain"

     

    }

     

    is it ok?

     

    how to use a effeicent way to cache this .com and .co.uk
  • how about this one?

     

     

    if { [string tolower [HTTP::host]] ends_with ".co.uk" } {

     

    set envdomain "[domain $host 3]"

     

    }

     

    elseif {[string tolower [HTTP::host]] ends_with ".com" } {

     

    set envdomain "[domain $host 2]"

     

    }

     

     

    HTTP::redirect "https://my.$domain"

     

  • Hi jucao,

    Take a look at the domain command. I think that your values need to be corrected from 3 / 2 to 2 / 1.

    http://devcentral.f5.com/wiki/iRules.domain.ashx

    
    when HTTP_REQUEST {
    if { [string tolower [HTTP::host]] ends_with ".co.uk" } {
    set envdomain "[domain $host 2]"
    }
    elseif {[string tolower [HTTP::host]] ends_with ".com" } {
    set envdomain "[domain $host 1]"
    }
    } 
    

    Everything else looks good. Let us know if you have any problems with it.