Forum Discussion

wg's avatar
wg
Icon for Nimbostratus rankNimbostratus
Feb 27, 2020

irule redirect to new site for http and https traffic

I need to create an irule to redirect traffic to a new site for both http and https.

My current rule is only working for http traffic, could use a hand on this as I don't have much experience with irule creation.

 

redirect traffic from 123.mydomain.com/random/stuff > abc.mydomain.com/random/stuff

current rule:

when HTTP_REQUEST { 

 if { [HTTP::uri] contains "/random/stuff/" } { 

  [HTTP::redirect "https://abc.mydomain.com[HTTP::uri]"

]

 }

}

 

 

 

4 Replies

  • NAG's avatar
    NAG
    Icon for Cirrostratus rankCirrostratus

    Hi,

    If you are handling both HTTP and HTTPS traffic, you should configure 2 Virtual servers. One listening on port 80 and the other listening on 443.

    If you want to redirect on both http and https, you have apply iRule on both the Virtual Servers.

    Here is are two examples::

    For temporary redirect::

    when HTTP_REQUEST { 
        if { [string tolower [HTTP::host]] contains "/random/stuff" } {      
                HTTP::redirect "https://abc.mydomain.com[HTTP::uri]"
            }
    }

    For permanent redirect:

    when HTTP_REQUEST { 
        if { [string tolower [HTTP::host]] contains "/random/stuff" } {      
                HTTP::respond 301 Location "https://abc.mydomain.com[HTTP::uri]"
            }
    }

    Hope this helps,

    Nag

    • wg's avatar
      wg
      Icon for Nimbostratus rankNimbostratus

      ​Hi NAG,  thank you for the quick response.  I should have mentioned that there are separate virtual servers for 80 and 443 and the rule had been applied to each VS separately.

       

      I left original irule attached to the port 80 vs as it was working as desired, I've applied your recommended permanent redirect to the 443 VS and attempted a few changes but the redirect does not appear to be firing, I'm going to set up logging to see what is causing this behavior.

       

      WG

      • NAG's avatar
        NAG
        Icon for Cirrostratus rankCirrostratus

        On the HTTPS VS, are you terminating the client side SSL connection on F5 or is it between Client and the back-end pool member ?

         

        For F5 to parse HTTP traffic, you should terminate client side SSL connection on F5.

         

        May be you are are aware of this but I just want to make sure you have looked it as well.