Forum Discussion

Krzysztof_52486's avatar
Krzysztof_52486
Icon for Nimbostratus rankNimbostratus
Jun 17, 2012

Redirect non www to www and http to https in one irule?

Hi all,

 

Is possible to in one irule redirect www to non www and http to https?

 

 

Ony one address are valid: https://host.domain.pl

 

but some users try to access: http://host.domain.pl or http://www.host.domain.pl or https://www.host.domain.pl - is possible to redirect all traffic to ONE valid address ?

 

 

All to -- > https://host.domain.pl

 

 

Thans for advice.

 

KP.

 

 

3 Replies

  • nathe's avatar
    nathe
    Icon for Cirrocumulus rankCirrocumulus
    KP

     

     

    Could this work:

     

     

    when HTTP_REQUEST {

     

     

    Check if the host starts with www.

     

    if {[string tolower [HTTP::host]] starts_with "www."}{

     

     

    Redirect with the www. prefix removed to the same URI

     

    HTTP::redirect "https://[string range [HTTP::host] 4 end][HTTP::uri]"

     

     

    } else {

     

     

    Redirect to https for http://host.domain.pl

     

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

     

     

    }

     

    }

     

     

    First bit re www taken from: https://devcentral.f5.com/Community/GroupDetails/tabid/1082223/asg/50/aft/1178449/showtab/groupforums/Default.aspx

     

     

    Hope this helps

     

    N
  • Hi nathan,

     

    Thanks for reply, yes, is't working, but still in one case had error:

     

     

    http://host.domain.pl - - > https://host.domain.pl - OK

     

    http://www.host.domain.pl - - > https://host.domain.pl - OK

     

    https://www.host.domain.pl - - > https://host.domain.pl - WRONG - certificate error :-/

     

     

    KP.
  • nathe's avatar
    nathe
    Icon for Cirrocumulus rankCirrocumulus
    KP

     

     

    If you check this post, which is exactly like yours, a Devcentral MVP suggests another cert on a VIP or a wildcard cert instead.

     

     

    https://devcentral.f5.com/Community/GroupDetails/tabid/1082223/asg/50/aft/813956/showtab/groupforums/Default.aspx

     

     

    Rgds

     

    N