Forum Discussion

MSK_222682's avatar
MSK_222682
Icon for Nimbostratus rankNimbostratus
Feb 04, 2016

URL redirection with retaining the original on browsers

Hi All,

I have a requirement whereby the user would try to access www.test.com but it needs to be redirected to www.test.abc.com, which is hosted in our environment. 

Business doesn't want to publish our brand name abc.com and therefore requested to retain only www.test.com in end user browsers.

Is there a way to achieve this using iRules ?

Quick response is highly appreciated.

Thanks in advance,
Sai

7 Replies

  • BinaryCanary_19's avatar
    BinaryCanary_19
    Historic F5 Account

    You can accomplish this with Rewrite Profile: https://support.f5.com/kb/en-us/products/big-ip_ltm/manuals/product/ltm-implementations-11-5-1/23.html?sr=51290275

     

    You could also point the DNS records for www.test.com to abc.com and simply use the same pool for abc.com as the pool for test.com. This will also require the web servers to be configured with a name virtual host (apache terminology) for test.com which uses the same web root as abc.com.

     

    • MSK_222682's avatar
      MSK_222682
      Icon for Nimbostratus rankNimbostratus
      Issue with playing DNS here is we do not own test.com and therefore cannot propagate in our DNS architecture
  • Are trying to convert the links inside the HTTP response from www.abc.test.com to www.test.com again?

    You can create a new stream profile to translate the domain names or use an iRule like this:

    when HTTP_REQUEST {
       set to_change 0
          if { [HTTP::path] contains "/urltomonitor" } {
             set to_change 1
       }
       STREAM::disable
    }
    
    when HTTP_RESPONSE {
       if { $to_change == 1} {
          set original "http://www.abc.test.com"
          set replacement "http://www.test.com"
          STREAM::expression "@$original@$replacement@"
          STREAM::enable
       }
    }
    

    You will need to modify the [HTTP::path] to match your url that contains redirection, and you still need to attach "stream" profile to your virtual server.

    • MSK_222682's avatar
      MSK_222682
      Icon for Nimbostratus rankNimbostratus
      Hi Minn, Thanks for your quick response. I shall test this iRule in test infra. But can you help me understand how this above iRule (the commands) in it would be interpreted by BIGIP as I'm new to BIGIP technology and iRule code. Also, whats the role of "stream" profile in this case. Thanks again, Sai
    • Minn_62043's avatar
      Minn_62043
      Icon for Cirrostratus rankCirrostratus
      So if a user is going to this url http://www.test.com/urltomonitor, and the page is redirecting the user to http://www.abc.test.com or if the page contains http://www.abc.test.com, iRule will replace that domain with http://www.test.com before sending the response to user, and user browser will never get to see www.abc.test.com.
  • zeiss_63263's avatar
    zeiss_63263
    Historic F5 Account

    "user would try to access www.test.com but it needs to be redirected to www.test.abc.com"

     

    The elephant in the room is whether you actually own test.com.

     

    After that, you don't need rewrites or redirection, you simply need to point the DNS record to the same IP as www.test.abc.com and tell the web servers that serve www.test.abc.com to serve the same page(s) when the HTTP "Host:" header contains www.test.com.

     

    Of course if your webpages contain hard links (rather than relative ones) you'll need to do some STREAM changes to alter URLs-on-the-fly, per the post from Minn.

     

    • MSK_222682's avatar
      MSK_222682
      Icon for Nimbostratus rankNimbostratus
      Hi Zeiss, We do not own test.com and therefore the problem. Let me try the iRule given by Minn and get back to you all. Thanks for the quick response. Sai