Forum Discussion

JohnnyBacchus's avatar
JohnnyBacchus
Icon for Nimbostratus rankNimbostratus
Aug 05, 2021

iRule Redirection Help

Hello,

 

I have a peculiar situation that I'm trying to figure out if iRules can pull off for me but I'm not sure about the approach here. For context, we have one DNS entry pointing directly to a server (we'll call this example1.com) and another DNS entry that points to an F5 VIP (we'll call this example2.com). Our client wants to have it where end users who enter https://example1.com/something get redirected to https://example2.com/something. I believe with iRules this wouldn't be possible unless we created a F5 VIP for example1.com and change the DNS entry to point to this new F5 VIP. So a new F5 https VIP was created that didn't load balance to anything but just existed so that the DNS entry for example1.com could point to it. So I'm looking for a method to be able to redirect end users who enter https://example1.com/something to https://example2.com/something. I thought this would be possible with something like this:

 

when HTTP_REQUEST {

  if { [HTTP::host] equals "example1.com" } {

  if { [HTTP::path] equals "/something" } { 

   HTTP::redirect "https://example2.com"

   }

  }

}

 

There's also an iRule applied to the VIP that example2.com points to for redirecting users who enter https://example2.com to https://example2.com/something, which is currently working. The idea was to have an iRule applied to the VIP of example1.com to redirect end users entering https://example1.com/something to https://example2.com and then the other iRule applied to the VIP that example2.com points to would handle the redirect to https://example2.com/something. However, this isn't working as planned and I'm not as knowledgeable with iRules to figure out alternatives.

  • Hi  ,

    You can try below iRule -

    when HTTP_REQUEST {
    if { [HTTP::host] equals "example1.com" }{
    if { [HTTP::uri] contains "something" }{ 
    HTTP::redirect "https://example2.com"
    }
    } 
    }

    Also below is the irule which will also help to redirect to the uri along with the host. So you shouldn't require separate irule to redirect to the uri if you want to keep same uri path.

    when HTTP_REQUEST {
    if { [HTTP::host] equals "example1.com" }{
    if { [HTTP::uri] contains "something" }{ 
    HTTP::redirect "https://example2.com[HTTP::uri]"
    }
    } 
    }

    Also if your F5s are running on 14.1.0 or later version, kindly consider - https://support.f5.com/csp/article/K23237429

    Hope it helps!

    • JohnnyBacchus's avatar
      JohnnyBacchus
      Icon for Nimbostratus rankNimbostratus

      Okay, I tried both of those iRule options and neither worked. We still receive an error message of 'ERR_CONNECTION_RESET'.

  •  Could you please check the article given above and see if it is applicable to you?