Forum Discussion

Joe_H_250786's avatar
Joe_H_250786
Icon for Nimbostratus rankNimbostratus
Feb 22, 2016

iRule for Secure All The Time Redirect

Hello,

 

We are trying to implement an iRule to forward all non-secure traffic (via 301) to secure and non-www to wwww

 

Example:

 

http to https http://domain.com -> https://www.domain.com http://www.domain.com -> https://www.domain.com http://www.domain.com/category -> https://www.domain.com/category http://domain.com/category -> https://www.domain.com/category

 

https non-www to https www https://domain.com -> https://www.domain.com https://domain.com/category -> https://www.domain.com/category

 

Thank you for your help

 

1 Reply

  • Hi Joe,

    you may try the iRule below as a starting point...

    when HTTP_REQUEST {
        if { [string tolower [HTTP::host]] starts_with "www." } then {
            HTTP::respond 301 Location "https://[getfield [HTTP::host] ":" 1][HTTP::uri]"
        } else {
            HTTP::respond 301 Location "https://www.[getfield [HTTP::host] ":" 1][HTTP::uri]"
        }
    }
    

    Cheers, Kai