Forum Discussion

Jesse_Reinhart_'s avatar
Jesse_Reinhart_
Icon for Nimbostratus rankNimbostratus
May 12, 2017

Redirect domain apex to www, retain URL/protocol

Hi!   We're proud owners of some new Big-IP virtual licenses. Being new to Big-IP, our iRule experience is little to none, so I was hoping we could get some assistance in generating an iRule that ...
  • Hannes_Rapp_162's avatar
    May 12, 2017

    Hi and welcome,

     

    Recommend to take a look at ready-made iRules in Codeshare to get started. Start by making minor adjustments to someone else's code and learn that way. Basic iRule writing skills are a must when working with BigIP LTM.

     

    This code will accomplish your current task

     

    when CLIENT_ACCEPTED {
         Default to HTTPS
        set proto "https"
        if { [TCP::local_port] eq "80" }{
             set proto "http"
        }
    }
    when HTTP_REQUEST {
        if { [string tolower [HTTP::host]] eq "website.com" }{
            HTTP::respond 301 Location "$proto://www.website.com[HTTP::uri]" Connection Close
            event disable
        }
    }

    Requires HTTP profile attached to your Virtual Server

     

    Rgds,