Forum Discussion

DoubleJz's avatar
DoubleJz
Icon for Nimbostratus rankNimbostratus
Oct 24, 2023

iRule or LTM Policy to pre-fix desired www. sites

I have an issue where if I browse to https://abc.com the page will not load ( connection timed out) but https://www.abc.com will load as desired.

Therefore, I believe I need to somehow modify the following iRule to check to see if it contains www. and if it doesn't add it. 

when HTTP_REQUEST {
 if { [class match [HTTP::host] equals Datagroup1] } {
  pool prod_sites
  } else {
  HTTP::respond 403
  }
}

However, I have a couple URIs in the data group that contains a subdomain that I don't want to prefix with www.

I know I can change it with the following but I'm struggling to determine a way to redirect those in Datagroup1 with exceptions. I'm assuming its going to be a messy if, elseif, else kinda of deal but having a hard time putting it all together and working.

when HTTP_REQUEST {
    if {[HTTP::host] eq "abc.com"} {
        HTTP::redirect "https://www.abc.com[HTTP::uri]"
    }
}

maybe specifying a not equal for exclusions ??

if { ([HTTP::host] ne "subdomain.cbs.com") } {

I also currently have a policy in place to redirect HTTP to HTTPS as follows:

Redirect to location 'tcl:https://[getfield [HTTP::host] : 1][HTTP::uri]' at request time.

Any suggestions would be greatly appreciated.

8 Replies

      • Okay, then it seems abc.com and www.abc.com are different sites and abc.com isn't configured to handel HTTPS traffic. In that case you are probably better of using two datagroups. One datagroup that lists all allowed hostnames and another that contains hostnames that should be excluded from having put www. to it. Then let the iRule decide if it's allowed and/or it's needs to be modified with the start of www.