Forum Discussion

Yugandhar's avatar
Yugandhar
Icon for Nimbostratus rankNimbostratus
Jun 09, 2018

Reg URL Redirection using IRule

Hi,

 

Is it possible to redirect a particular HTTP request to a particular URL based on the hostname and all other HTTP requests for that VIP to another URL using the following iRule.

 

when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "site.com" } { HTTP::redirect "https://yoursite1.com"; } else {HTTP::redirect "https://mysite09.com";}

 

}

 

Is it mandatory to use [string tolower ] when we are matching a [HTTP::host] Or can the iRule be written as

 

when HTTP_REQUEST { if { [HTTP::host] equals "site.com" } { HTTP::redirect "https://yoursite1.com"; } else {HTTP::redirect "https://mysite09.com";}

 

}

 

Thanks,

 

Yugandhar.

 

  • Yes, this is possible. The

    string tolower
    function isn't mandatory, but it's probably better to use it so you will catch all upper- and lowercase variations of the hostname.

    I see you use semicolons in your iRule. You don't need these.