Forum Discussion

farache_28983's avatar
farache_28983
Icon for Nimbostratus rankNimbostratus
May 14, 2012

Redirect request to different pools and rewrite the URL

I am trying to write an iRule that will rewrite the URL from a user request to a new URL and and a URI.

 

 

The request goes to: site1.com/communities but the content is served from site2.com (different pool)

 

 

 

All this needs to happen on the backgroup and the client URL cannot change. So they will still see site1.com/communities

 

 

 

or

 

 

 

The user will enter site.mydomain.com and be sent to newsite.newdomain.com/page1/page2... While this happens the displayed URL should not change and remain site.mydomain.com.

 

 

 

So far I've done this:

 

 

 

when HTTP_REQUEST {

 

if { [HTTP::uri] ends_with "/communities/default.aspx"} {

 

pool cmnty_pool

 

} elseif { [HTTP::uri] ends_with "/communities/video"} {

 

pool cmnty-video_pool

 

}

 

}

 

 

 

 

 

but this rules does not keep the URL intact and displays the pool b URL

 

 

 

thanks,

 

 

7 Replies

  • Are the URI's the same on both pools or is the new server doing some sort of redirect when you use the old site URI?
  • nathe's avatar
    nathe
    Icon for Cirrocumulus rankCirrocumulus
    farache

     

     

    Check out Joe's blog who explains about redirection and URIs and should help you: https://devcentral.f5.com/weblogs/Joe/archive/2005/07/27/ModifyingUriWithoutRedirect.aspx

     

     

    So you could use something like:

     

     

    when HTTP_REQUEST {

     

    if { ([HTTP::host] eq "site1.com") && ([HTTP::uri] eq "/communities" } {

     

    HTTP::header replace "Host" "site2.com"

     

    HTTP::uri "/someother_uri"

     

    }

     

    }

     

     

    So, site1.com/communities would be rewritten as site2.com/someother_uri but the browser would not change. Obviously you may have to tweak this looking at your example above but this should get you on your way.

     

     

    Does this help at all?

     

     

    N

     

     

     

  • Hey brian,

     

     

    No.. the URI are not the same on either pool..

     

     

     

    I am the one doing the redirect to a different pool when the request comes in, so technically the request never reaches pool A when request A with URI "/communities" comes in...

     

     

     

    http_request to sitea--> VIP A-->Pool A (default pool)

     

     

     

    http_request to sitea/communities--> VIP A --> PoolB (new site with address www.siteB.com) but on the browser still has to look like "sitea/communities "

     

     

     

    I hope this helps

     

     

     

    thanks man,

     

    Francisco

     

  • hey Frache, Can you try this..

     

     

     

     

    when HTTP_REQUEST {

     

    if { ([HTTP::uri] starts_with "/communities") } {

     

    pool pool_b

     

    } else { pool pool_a }

     

    }
  • John_Alam_45640's avatar
    John_Alam_45640
    Historic F5 Account
    I think that you need the proxypass iRule. Look at this link,

     

    https://devcentral.f5.com/wiki/iRules.proxypassv10.ashx

     

     

    Read the usage information carefully.

     

     

    john
  • I understand that you are trying to get the traffic to a different pool, but I was asking whether the new pool servers require a different path in order to serve up the same content. For example, if "http://oldsite.com/communities" translates to "http://newsite.com/differentcommunity", then you should do the following:

    
    when HTTP_REQUEST {
        if { [HTTP::uri] eq "/communities" }{
            HTTP::path "/differentcommunity"
            pool pool_b
        }
        else {
            pool pool_a
        }
    }
    

    My guess is that the new webserver is in fact redirecting the traffic to it's URL since it does not answer to the same PATH...does that make sense?