Forum Discussion

Ashish_R_G_2512's avatar
Ashish_R_G_2512
Icon for Nimbostratus rankNimbostratus
Oct 24, 2016

Redirect www to https

Hi,

 

I have configured an HTTP VIP and configured irule to redirect all HTTP traffic to HTTPS VIP which I have created. It is working fine as expected. Below are the script which i have used.

 

when HTTP_REQUEST {

 

HTTP::redirect "https://[HTTP::host][HTTP::uri]”

 

}

 

I want to create another rule when someone try to access http://www.abc.com it should be redirected to https://abc.com i.e. I need to remove the www and also it should be redirected to HTTPS VIP. Is there any way to achieve this.

 

Thank you,

 

Ashish R

 

1 Reply

  • Try this:

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

    If you are looking for a generic rule, you can try something like this:

    when HTTP_REQUEST {
    if { [HTTP::host] starts_with "www." } {
    HTTP::redirect "https://[getfield [HTTP::host] "www." 2][HTTP::uri]”
    }