iRule assistance with redirecting to a different pool and URI

Hi Everyone, I am relatively green when it comes to irules and would like some assistance setting one up.

We have been asked to redirect everything under a particular site. Eg: http://oldserver.contoso.com/department/oldsitename/ To be redirected to a new server with a different URI: http://newserver.contoso.com/business/department/newsitename/ However, they want the browser to display the old host name with the new URI: http://oldserver.contoso.com/business/department/newsite/

Since we need to this for over 100 URLs. I thought that the best way to accomplish this would be to use Data Groups. The problem I have is that we would need to redirect clients to a different pool with a modified URI.

The following code works great for redirecting to a different host and different URI using data groups, but I need something that would redirect to a different pool and different URI.

when HTTP_REQUEST {
    if { [string tolower [getfield [HTTP::host] ":" 1]] equals "oldserver.contoso.com" } {
        set p [URI::path [string tolower [HTTP::uri]] 1 3]
        log local0. "Variable p set to: $p"
        set m [class match -value $p equals dg_redirect_shpt_paths]
        log local0. "Variable m set to: $m"
        if { $m ne "" } {
            HTTP::respond 301 noserver Location " http://newserver.contoso.com[string map -nocase "$p $m" [HTTP::uri]]"
        }
        unset -nocomplain p m
    }
}

Any advice would be great. Thanks, Chris

Hello you have a conflicting statement in your question :slight_smile:

You cant have http://oldserver.contoso.com/department/oldsitename/ redirect to http://newserver.contoso.com/business/department/newsitename/ as that would mean the client is following that redirect and the browser would show: http://newserver.contoso.com/business/department/newsitename/

So I think you need to decide if you want the client to still be accessing the old hostname but with a new url or if you want a whole new host and url.

Once I know that we can build the irule. In short a redirect redirects the client browser, so I dont think you want a redirect if you want the old host name.