Forum Discussion

Jeff_Barnett_41's avatar
Jeff_Barnett_41
Icon for Nimbostratus rankNimbostratus
Dec 24, 2014

URL redirect to another

I am new to the F5 I need to create a simple Irule that redirects one URL to another. here is what I have, that does not work:

 

when HTTP_REQUEST { if { (([HTTP::host] equals "abc.com/sonar")) } { HTTP::redirect "https://abc.com/sonar/sessions/new?return_to=%2Fsonar%2F" } else {HTTP::redirect https://[HTTP::host][HTTP::uri]} }

 

But this does not work it only picks up the second condition and redirects http to https. any help would be great.

 

3 Replies

  • can you try something like this?

    when HTTP_REQUEST { 
      if { [HTTP::host] equals "abc.com" and [HTTP::path] equals "/sonar" } { 
        HTTP::redirect "https://abc.com/sonar/sessions/new?return_to=%2Fsonar%2F" 
      } else {
        HTTP::redirect "https://[HTTP::host][HTTP::uri]"
      } 
    }
    
  • HTTP::host will never match abc.com/sonar, it would only match abc.com You need to use HTTP::host to match the host, and HTTP::uri to match the path.

    when HTTP_REQUEST {
        if { (([string tolower [HTTP::host]] equals "abc.com") and ([string tolower [HTTP::uri]] equals "/sonar")) {
            HTTP::redirect "https://abc.com/sonar/sessions/new?return_to=%2Fsonar%2F"
        } else {
            HTTP::redirect https://[HTTP::host][HTTP::uri]
        }
    

    I think that should world. You can also do this with an HTTPClass or policy(depending on your LTM version) instead of an iRule.

  • I need a very similar iRule as the first example, but where the case of /sonar can be either /sonar or /Sonar. I tried the second example, but it does not work. I tried to modify the first one to;

     

    when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "abc.com" and [HTTP::path] equals "/sonar" } { HTTP::redirect "https://domain.site.com } else { HTTP::redirect "https://[HTTP::host][HTTP::uri]" } }

     

    But that doesn't work for me. I would appreciate any help or suggestions.