Forum Discussion

plavender_72604's avatar
plavender_72604
Icon for Nimbostratus rankNimbostratus
May 12, 2010

URL rewrites for multiple domains

Hopefully someone can help me out here, scripting is not my strong point and each time I try to search this forum I get an error :-(

 

 

I would like to set up the F5 so that multiple sub domains get the URL rewritten and then directed to a specific pool.

 

 

For example:

 

 

http://aaa.domain.com gets a url rewrite to http://domain.com/aaa and the traffic gets sent to pool aaa

 

 

http://bbb.domain.com gets a url rewrite to http://domain.com/bbb and the traffic gets sent to pool bbb

 

 

Any help will be greatly appreciated!

 

 

Thanks in advance!

 

5 Replies

  • Hey All,

    I've had a go at trying to put something together, could someone just give it a sanity check?

    when HTTP_REQUEST {

      
         Check host/uri (set to lowercase) switch "[string tolower [HTTP::host]]" { 
      
           "aaa.domain.com" { 
      
               Rewrite host/URI 
              HTTP::header replace Host "domain.com" 
              HTTP::uri "/aaa" 
      pool aaa_pool
           } 
           "bbb.domain.com" { 
      
               Rewrite host/URI 
              HTTP::header replace Host "domain.com" 
              HTTP::uri "/bbb" 
              pool bbb_pool
           } 
        } 
     } 
    Thanks again!
    Peter
  • Hi Peter,

    Nice work; that looks like a good start. One small thing: do you want to prepend /aaa or /bbb to all URIs, or just if the requested URI is /?

    For the former, you could use something like this:

    
    if {not ([HTTP::path] starts_with "/aaa")}{
       HTTP::path "/aaa[HTTP::path]"
    }
    

    And for the latter:

    
    if {[HTTP::path] eq "/"}{
       HTTP::path "/aaa[HTTP::path]"
    }
    

    Aaron
  • Hi Aaron,

    Many thanks for the response! So at the moment, what we are trying to do is rewrite from aaa.domain.com to domain.com/aaa. Once the rewrite has happened, we need the requests to stay with the /aaa or /bbb as the path, so I'm not too sure if I'd need to add your suggestion or not?

    I've also just remembered, that we are using another iRule to change pools if there is less than 2 servers available:

    when HTTP_REQUEST {
      if { [active_members http_pool] >= 2 } {
        pool primary_pool
    } else {
    pool alternate_pool

    }

    }

    So I am guessing, the iRule would need to be configured as follows:

     when HTTP_REQUEST { 
      
         Check host/uri (set to lowercase) 
        switch "[string tolower [HTTP::host]]" { 
      
           "aaa.domain.com" { 
      
               Rewrite host/URI 
              HTTP::header replace Host "domain.com" 
              HTTP::uri "/aaa" 
    if { [active_members http_pool] >= 2 } {
        pool aaa_pool
    } else {
    pool aaa_alternate_pool
           } 
    Thanks again!
    Peter
  •  

    So at the moment, what we are trying to do is rewrite from aaa.domain.com to domain.com/aaa. Once the rewrite has happened, we need the requests to stay with the /aaa or /bbb as the path, so I'm not too sure if I'd need to add your suggestion or not?

     

     

     

    I think you'd want to always prepend /aaa or /bbb to the URI if it wasn't there already as in the first example code snippet above.

     

     

    And your code for checking the aaa_pool before using it should work fine.

     

     

    Aaron