Forum Discussion

kraigk_52257's avatar
kraigk_52257
Icon for Nimbostratus rankNimbostratus
Aug 30, 2013

Another http redirect question

I've scoured devcentral and google and haven't found my answer. I'm trying to redirect http based on header. A CNAME gets traffic to our VIP as well as straight http that needs to be redirected to https. http to https iRule has been in place and working for a long time I'm just trying to add this other header. Is this possible?

when HTTP_REQUEST { 
    if { [HTTP::host] contains "mail.domain.com"} { 
    HTTP::redirect https://[HTTP::host][HTTP::uri]

   if { [HTTP::host] contains "exchange.mail.com"} {
    HTTP::redirect http://www.domain.com/page.html[HTTP::uri]} } }

7 Replies

  • The first condition does more or less what the default http-to-https code does. Are you using this iRule in addition to another iRule?

     

    when HTTP_REQUEST {
        switch [string tolower [HTTP::host]] {
            "mail.domain.com" {
                HTTP::redirect "https://[HTTP::host][HTTP::uri]"
            }
            "exchange.mail.com" {
                HTTP::redirect "http://www.domain.com/page.html[HTTP::uri]"
            }
        }
    }

    Though I might add that the URI "/page.html[HTTP::uri]" doesn't really make sense. If the request URI was "/foo", then you'd redirecting them to "/page.html/foo".

     

  • Kevin,

     

    That worked like a charm. Can you get me a solution faster next time? :-)

     

    thanks much.

     

  • A question just occurred to me. Not sure if this is possible.. is there a way to redirect this whether or it comes in http or https? Add a third condition?

    "exchange.mail.com" {
                HTTP::redirect "http://www.domain.com/page.html[HTTP::uri]"
            }
        }
    }
    
  • Not sure I understand. If this is on the HTTP VIP, it'll come in HTTP://, likewise for the HTTPS VIP.

     

  • So the above you provided works great provided the exchange.domain.com is browsed via http://exchange.domain.com. If https://exchange.domain.com it doesn't redirect.

     

  • Can I assume you have separate HTTP and HTTPS VIPS? If so, put that section of code in an iRule on the HTTPS VIP.