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

Sonny_J_Bonds_1's avatar
Sonny_J_Bonds_1
Icon for Nimbostratus rankNimbostratus
Jun 09, 2015

http to https redirect working but want to add www.

Hi,

This iRule is working to redirect http to https and leaving the hostname intact. Exactly what I want.

when HTTP_REQUEST {
       HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]
    }

My problem here is, when customers type in http://abc.com (notice no ) I want it to redirect to https://www.abc.com not just https://abc.com which is giving me a cert error.

How would you write the if/else statement so www. appends to the request?

Thank you in advance.

4 Replies

  • Hi Sonny,

     

    Please try with the irule below.

     

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

     

    Thanks.

     

    Anto

     

  • Your irule does not include uppercase URLs:

    the following irule will allow you to redirect needed hosts:

    when HTTP_REQUEST {
        switch -glob [string tolower [HTTP::host]] {
            "abc.com" -
            "www.abc.com" -
            "*.abc.com" { HTTP::redirect https://www.abc.com[HTTP::uri] }
        }
    }
    

    I added www.abc.com and *.abc.com to show different ways with switch command.