Forum Discussion

Alan_Johnson_FB's avatar
Alan_Johnson_FB
Icon for Nimbostratus rankNimbostratus
Jul 06, 2017

If URL contains [blank] redirect to original URL @ different port

Hi folks,

 

I'm trying to setup what I believe is a fairly simple redirect iRule but a total lack of experience has me stumped. Here's what I'm trying to accomplish:

 

If a client hits a URL containing "synchrony" then they will be redirected to the same URL with port 8091.

 

As an example:

 

or

 

Here's the iRule I'm currently using:

 

when HTTP_REQUEST { if { [string tolower [HTTP::uri]] contains "/synchrony" && [TCP::local_port] == 80 } { HTTP::redirect "http://[getfield [HTTP::host] ":" 1]:8091/[URI::basename [HTTP::uri]]" } }

 

...which works fine on the first example, but fails if the url contains anything after "/synchrony".

 

Any guidance would be greatly appreciated.

 

2 Replies

  • P_K's avatar
    P_K
    Icon for Altostratus rankAltostratus

    what do you see when using starts_with "/synchrony" ??

     

  • P_K's avatar
    P_K
    Icon for Altostratus rankAltostratus

    This should work!

     

    when HTTP_REQUEST {

     

    if {

     

    [string tolower [HTTP::uri]] contains "/synchrony" && [TCP::local_port] == 80 }

     

    { HTTP::redirect "http://[getfield [HTTP::host] ":" 1]:8091[HTTP::uri]"

     

    }

     

    }