Forum Discussion

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

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 would do the following:

 

Redirect website.com to , retaining protocol (HTTP or HTTPS) and the full URL, but NOT do this for subdomains.

 

For example: https://website.com/pages/subpage.html redirects to https://www.website.com/pages/subpage.html and http://website.com redirects to http://www.website.com but https://subdomain.website.com does NOT redirect

 

Does anybody have an iRule that does this, or is there a better way to do it in Big-IP LTM? I realize it might be specific with retaining the full path and protocol but excluding subdomains.

 

Thanks for any help you guys can provide!

 

  • Jesse
  • 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,

     

4 Replies

  • 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,

     

  • 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,