NetScaler content switching vs. F5 iRule - instream rewrite

I am migrating a configuration from NetScaler to F5. I need to replicate the content switching capability on the NetScaler with an iRule on the F5. The client sends “/path1/file.aspx” the server sees “/path2/file.aspx”. I also need to reverse it on the way back out, so that the client always sees “/path1/file.aspx”. The code for the inbound rewrite is easy… when HTTP_REQUEST { HTTP::uri [string map {“/path1/file.aspx” “/path2/file.aspx”} [HTTP::uri]] } How do I so the same on the outbound. I assume I have to use an HTTP_RESPONSE event, but the syntax is eluding me. Cane someone offer some assistance? Or better yet, a code example?

when HTTP_RESPONSE{ HTTP::uri [string map {“/path2/file.aspx” “/path1/file.aspx”} [HTTP::uri]] }

Unfortuately, that won’t work. The LTM gives me the following error: 1070151:3: Rule [/Common/dbrewrite] error: /Common/dbrewrite:4: error: [unknown event (HTTP_RESPONSE{)][when HTTP_RESPONSE{ HTTP::uri [string map {“/path2/file.aspx” “/path1/file.aspx”} [HTTP::uri]] }]

I tried that originally. Unfortunately, the HTTP_RESPONSE and the HTTP_REQUEST have totaly different command options. I cannot use an HTTP::uri in the RESPONSE event.

There is no HTTP::uri object in an HTTP response since the URI is the requested resource location in a request. Are you trying to replace references to the URI in the response content or a redirect location?

Maybe something like this in the HTTP_RESPONSE event. Make sure to enable stream profile on the VIP. if {[HTTP::header value Content-Type] contains “text”} {STREAM::expression {@/path2/file.aspx@/path1/file.aspx@} }

I am trying to reverse the HTTP_REQUEST action taken.

I’ll try that R Eastman and let you know what comes about… thanks.

Matthew, everything you need can be found here: DevCentral - An F5 Technical Community

Rather than going the irule route, what about the new Rewrite profiles? 404 Page not found | BIG-IP Documentation