Forum Discussion

Ema's avatar
Ema
Icon for Nimbostratus rankNimbostratus
Aug 23, 2019

Irule for www removal on https

I would like to remove the www from the url but is having some issues with the code on one of my vip.

I currently have 2 vips:

1 is for http redirection to https with that includes the www removal and no pools attached. This is working correctly.

My other vip which is just a https vip with a pool attach that is not working and this is the irule I have attached to it.

  1. when HTTP_REQUEST {
  2. if {[string tolower [HTTP::host]] starts_with "www."}{
  3. HTTP::redirect "https://[string map {www. ""} [string tolower [HTTP::host]]]"
  4. }
  5. }

 

So when I type in https://www.abc.company.com it is not redirecting for the HTTPS vip but when I use www.abc.company.com the HTTP vip redirects me to the correct url abc.company.com.

Thanks in advance for the help.

 

  • Hi,

    Can you try this iRule in browser's incognito mode?

    when HTTP_REQUEST {
        if {[string tolower [HTTP::host]] starts_with "www."}{
            log local0. "hostname = [HTTP::host]"
            HTTP::redirect "https://[substr [HTTP::host] 4][HTTP::uri]"
        }
    }

  • Hi Ema,

     

    This may be due to other an iRule priority. Does the https VS have any other iRules?

  • Ema's avatar
    Ema
    Icon for Nimbostratus rankNimbostratus

    Hi Eaa,

     

    The vs doesn't have any other irules attached to it.

     

     

  • Hi,

    Can you try this iRule in browser's incognito mode?

    when HTTP_REQUEST {
        if {[string tolower [HTTP::host]] starts_with "www."}{
            log local0. "hostname = [HTTP::host]"
            HTTP::redirect "https://[substr [HTTP::host] 4][HTTP::uri]"
        }
    }

    • Ema's avatar
      Ema
      Icon for Nimbostratus rankNimbostratus

      Hi eaa,

       

      This is strange that when I apply that iRule I don't see a log entry inside of /val/log/ltm for what I'm expecting hostname = www.abc.company.com. The only thing that I see is that the SSL Handshake failed which mean that for some reason it is skipping this irule. Any ideas as to why? The only thing that is different on this VS is that there is a pool assosiated with this and the other VS doesn't.

       

      Thanks

      • David_M's avatar
        David_M
        Icon for Cirrostratus rankCirrostratus

        Sounds like the ssl handshake fails because the CN name on the certificate doesn't match once you trim it?