For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

RoyDShaw_195277's avatar
RoyDShaw_195277
Icon for Nimbostratus rankNimbostratus
Jun 01, 2015

URI and Header Host file replace

I am having a hard time trying to figure out Irule to do the following.

If a user hits https://whateverwebsite.com/static/test.html or /static/test/test.html. etch

I want that to get redirected to another domain but it no do a 302 it just rewrites the response. Now I have figured out how to the the hostname but I can never get it to work with the URI. Also i basically only want it to do it just for the that one URI and nothing else. Also if a user types anything after that URI i want it to redirect that.

So

whatever.com goes to my F5 pool

whateever.com/static "anything behind that" gets header rewrite without a 302.

This is what I have used for the Host and it seems to work, just configure out the URI.

when HTTP_REQUEST { Remove the Accept-Encoding header from requests so that the server does not compress responses HTTP::header remove Accept-Encoding

 Disable the STREAM profile for request traffic
STREAM::disable

 replace the Host header

if { [HTTP::uri] starts_with "/static" } { HTTP::header replace Host "whaterver.com"} } when HTTP_RESPONSE { Look for and replace redirects from the server if { [HTTP::header exists Location] } { HTTP::respond 200 HTTP::header replace Location [string map {"whaterver.com" "newwhaterver.com"} [HTTP::header Location]] }

 For any text-based response enable a STREAM mapping to replace specific values
 To use this, enable an empty STREAM profile to the virtual server
if { [HTTP::header Content-Type] contains "text" } {
    STREAM::expression {@whaterver.com@newwhaterver.com@}
    STREAM::enable
}

}

6 Replies

  • I want the URI to stay the same, just want the hostname to change. But I only want the hostname to change if that URI is present.

     

    So if a user goes to oldsite.com\static\whatever

     

    F5 responds with

     

    newsite.com\static\whaterver

     

    • nitass's avatar
      nitass
      Icon for Employee rankEmployee
      isn't it what HTTP::header replace in your irule does? HTTP::header replace Host "whaterver.com"
  • Yes and if I just put in whatever.com it actually works. I see it return with a 200 and the new hostname. It just anytime I add the \static URI at the end it does not work.

     

    • nitass's avatar
      nitass
      Icon for Employee rankEmployee
      uri (e.g. /static) is not part of host header.
  • Yeah, I am trying to figure out how to make the host header change when that URI comes up.