Forum Discussion

Christian_Meiss's avatar
Christian_Meiss
Icon for Nimbostratus rankNimbostratus
Aug 05, 2016

simulate special mod_proxy behaviour

Hi folk,

I can reproduce the following

        ProxyPass /foo http://host.domain.tld/foo

with

if {[HTTP::uri] eq "/foo"}{
    pool target_pool
}

But i'm not able to do this:

        ProxyPass /foo http://host.domain.tld/bar

I need something like this:

if {[HTTP::uri] eq "/foo"}{
    pool target_pool /bar
}

But this is not available.

I tried this but this is not handy because /bar can also be a location on local

if {[HTTP::uri] eq "/foo"}{
    HTTP::redirect /bar
    pool target_pool
}

Any suggestions?

Cheers Christian

1 Reply

  • Hi Christian,

    to translate the

    [HTTP::uri]
    while forwarding the request to your internal server, you could use the rather simple iRule below. The
    [string range]
    command will simply strip the first four chars (e.g.
    /foo
    ) from the original URI and substitute the internal path (e.g.
    /bar
    ) into a new
    [HTTP::uri]
    value.

    if { [string tolower [HTTP::uri]] starts_with "/foo" } then {
            HTTP::uri "/bar[string range [HTTP::uri] 4 end]"
            pool bar_pool
    }
    

    But depending on your application requirements, you may also need to translate

    [HTTP::header value Referer]
    values on each request and untranslate
    [HTTP::header value Location]
    ,
    [HTTP::header value Content-Location]
    ,
    [HTTP::cookie domain]
    ,
    [HTTP::cookie path]
    and even embeded links in
    [HTTP::payload]
    on each response to reflect the external URI namespace.

    Note: Personally I always try to avoid hostname and path translation as much as possible. It makes stuff more complex and prone to errors...

    I'd like to encourage you to take a look to the existing ProxyPass iRule on CodeShare. It has a really great functionality and provides most of the functionality of the original Apache ProxyPass module.

    https://devcentral.f5.com/codeshare/proxypass-v10-v11

    Cheers, Kai