Forum Discussion

Justin_Haggerty's avatar
Justin_Haggerty
Icon for Nimbostratus rankNimbostratus
Jun 14, 2007

rewrite issue

Say our app behind our bigip answers up to www.xyz.com from the web. the server behind the bigip's hostname is actually www.abc.com. My current setup is working except for instances when people browse to say www.xyz.com/admin/ there browser then tries to load www.abc.com/admin/index.html. This eventually times out as www.abc.com isn't open to the world. What I'm looking to do is get that redirect to go to www.xyz.com/admin/index.html.

I wrote the following irule, but it doesn't seem to be working. They still get sent to abc.com.


when HTTP_REQUEST {
  if { [HTTP::host] contains "abc.com" } {
    HTTP::redirect "https://www.xyz.com/[HTTP::uri]"
  }
}

Any help would be greatly appreciated.

3 Replies

  • Deb_Allen_18's avatar
    Deb_Allen_18
    Historic F5 Account
    (moved your post to the proper forum)

     

     

    Your iRule looks fine.

     

     

    Not sure what you mean when you say users "browse to www.xyz.com/admin/... (but) browser then tries to load www.abc.com/admin/index.html". If the abc.com URI is showing up in the browser, there must be a server-originated redirect or something else going on between the user requesting the xyz.com URI and the failed request to abc.com.

     

     

    I see you are redirecting to HTTPS. If the original request is also HTTPS, you must decrypt the traffic with a clientssl profile before you can read the host header to determine if a redirect is in order.

     

     

    HTH

     

    /deb
  • the problem i'm seeing is when some one doesn't specify the actual file name. like /admin instead of /admin/index.html. apache knows to look for index.html in the directory and redirect to that page. But it is redirecting to the wrong hostname. They're getting sent to abc.com/admin/index.html, they requested xyz.com/admin/.

     

     

    I'm guessing we could set the apache config to use the hostname xyz.com, but the customer was wondering if the f5 could fix this instead.

     

     

    as for ssl, that was a typo. it should have just said http in the irule.
  • What's happening is that the backend webserver is sending a 301 or 302 based redirect to the browser. The redirect is in the HTTP response header named Location. For your situation, all you'll need to do is catch 301 or 302 responses in the Response and replace abc.com with xyz.com in the response value. Something like this should work for you.

    when HTTP_RESPONSE {
      switch [HTTP::status] {
        301 -
        302 {
          HTTP::header Location [string map {abc.com xyz.com} [HTTP::header Location]]
        }
      }
    }

    Basically this iRule will look in the response for all 301 and 302 status codes and if one is found, then set the Location header to the old location header with the strings "abc.com" replaced with "xyz.com".

    -Joe