Forum Discussion

Tyranon_113005's avatar
Tyranon_113005
Icon for Nimbostratus rankNimbostratus
Aug 28, 2018

[iRules]redirect to other site or pool

Hi, I'm trying redirect by host name.

 

When the access http://aaa.com, redirect to https://bbb.com When the access https://bbb.com, just through to pool related to VS bbb.com.

 

I set like below, but error has appeared 01070151:3: Rule [/Common/redirect_irule name] error: /Common/redirect_irule name:5: error: [undefined procedure: elseif][elseif { [HTTP::host] equals bbb.com }{ pool bbb.com }] ''

 

How I should correct?

 

when HTTP_REQUEST { if { [HTTP::host] equals "aaa.com" }{ redirect "https://bbb.com[HTTP::uri]" } elseif { [HTTP::host] equals "bbb.com" }{ pool bbb.com } }

 

2 Replies

  • Hi Tyranon,

    Try the below,

    when HTTP_REQUEST { 
    if { [HTTP::host] equals "aaa.com" } { 
    HTTP::redirect "https://bbb.com[HTTP::uri]" 
    } elseif { [HTTP::host] equals "bbb.com" } { 
    pool bbb.com
    } 
    }
    

    BTW if your VS already has the default pool which is bbb.com, you dont need the elseif condition, because the host is ultimately going to be bbb.com and it would just process the traffic and send to the VS pool, so below irule can be used too,

    when HTTP_REQUEST { 
    if { [HTTP::host] equals "aaa.com" } {
    HTTP::redirect "https://bbb.com[HTTP::uri]"
    }
    }
    
  • Hi Tyranon,

    Try the below,

    when HTTP_REQUEST { 
    if { [HTTP::host] equals "aaa.com" } { 
    HTTP::redirect "https://bbb.com[HTTP::uri]" 
    } elseif { [HTTP::host] equals "bbb.com" } { 
    pool bbb.com
    } 
    }
    

    BTW if your VS already has the default pool which is bbb.com, you dont need the elseif condition, because the host is ultimately going to be bbb.com and it would just process the traffic and send to the VS pool, so below irule can be used too,

    when HTTP_REQUEST { 
    if { [HTTP::host] equals "aaa.com" } {
    HTTP::redirect "https://bbb.com[HTTP::uri]"
    }
    }