Forum Discussion

Angela_R_33237's avatar
Angela_R_33237
Icon for Nimbostratus rankNimbostratus
Oct 19, 2005

Simple iRule help (I hope) -- non-www to www.

 

How do I set up an iRule to redirect non-www requests to the www of that domain.

 

 

Example:

 

 

domain1.com --> www.domain1.com

 

domain2.com --> www.domain2.com

 

 

We have about 100 of these sites so ideally I'd like to be able to set up one iRule for all of them.

 

 

Any help is appreciated!

 

 

Angela

6 Replies

  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    Your rule would indeed be simple. It'd be something like:

    
    when HTTP_REQUEST {
      if {[string tolower [HTTP::host] ] contains "www" } {
        pool your_poolname
      } else {
        HTTP::redirect "http://www.[HTTP::host][HTTP::uri]"
      }
    }

    Hope this helps,

    -Colin
  • Wonderful -- thanks! This is what I ended up using:

    
    when HTTP_REQUEST { if { ([HTTP::host] starts_with "www.") } { 
    pool pool_name } else { HTTP::redirect "http://www.[HTTP::host][HTTP::uri]"  } }

    Sorry, it's not very pretty. But it works -- thanks!
  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    Often times people find it beneficial to add logic like this to the network layer, rather than the application itself. Not only does it provide for greater flexibility in general, but it avoids needing to schedule a code-base change for your application, which for some peeople can be quite a process.

     

     

    -Colin
  • That's the message I've tried to preach at the last two companies I've worked for, the problem I've faced is the political machine. It's all about control, and the app developers want it all.

     

     

    Something we are going to do as a network services shop is to do an internal "road show" to all of our application development teams, showing off what BigIP can do for, allow them to have an opportunity to make requests as to what they would like to hand off to the BigIP, and what hooks they would like to develop to shape traffic. This will hopefully bring down the wall and help them realize that the once distinct line between application and network is no more.