For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

canuck's avatar
canuck
Icon for Altostratus rankAltostratus
May 31, 2018

URL redirect with multiple FQDNs

I am trying to define an iRule which will match any domain, adding www prefix and passing on. For example, if a user browses to http://abc.com or https://abc.com, redirects to https://www.abc.com. Same for def.com, jkl.com, etc.

I tried adding this:

 when HTTP_REQUEST {
    if { [string tolower [HTTP::host]] contains"www" } {
        HTTP::redirect "https://www[HTTP::host][HTTP::uri]"
    }
    else {[HTTP::redirect] "https://www.[HTTP::host][HTTP::uri]"}
}

but it broke my test sites. Prefer to avoid specifying FQDNs as I need to match 70+ sites.

What am I missing?

Thank you

2 Replies

  • Slightly modified the iRule.

    when HTTP_REQUEST {
         if { [string tolower [HTTP::host]] contains"www" } {
            HTTP::redirect "https://[getfield [HTTP::host] ":" 1][HTTP::uri]" }
         else { HTTP::redirect "https://www.[getfield [HTTP::host] ":" 1][HTTP::uri]" }
           }