Forum Discussion

Lucilius_223799's avatar
Lucilius_223799
Icon for Nimbostratus rankNimbostratus
Jan 14, 2016

Redirect issue (Global http to https but one website)

Hello everyone,

 

My goal was to redirect everything to https but one website. This website has to stay on http.

 

I have with some looking around and working up created the following code:

 

    when HTTP_REQUEST {
  switch [string tolower [HTTP::host][HTTP::uri]] {
    "http://www.abc.com/xyz/def" 
     {
      return
      do nothing
     }
    default {
      HTTP::respond 302 location "https://[HTTP::host][HTTP::uri]"
      event disable
      TCP::close
     }
  }
}

The issue I have is that www.abc.com/xyz/def is suffering from "Too many redirects loop" is this due to the code being erroneous? This is the only iRule currently attached to the virtual server.

 

Any help would be appreciated and thank you in advance!

 

8 Replies

  • Take the http:// part out of your first switch conditional. also you may want to use the glob parameter in the switch. IE switch -glob then make your condition end with a * since I assume you may have some longer paths and possible query parameters. HTTTP::uri includes query parameters.

     

    • Lucilius_223799's avatar
      Lucilius_223799
      Icon for Nimbostratus rankNimbostratus
      Thank you for the answer Brad, I changed the iRule with your recommendations. However the pages that shouldn't be redirected to https are still going to https from what I can see and are stuck in an a redirect loop. I wonder if it is something on the other side that is causing that issue though and not the iRule itself.
    • Kai_Wilke's avatar
      Kai_Wilke
      Icon for MVP rankMVP
      Please post your changed iRule, so that we can find the incorrect parts... ;-)
    • Brad_Parker_139's avatar
      Brad_Parker_139
      Icon for Nacreous rankNacreous
      Lets take one step back and see if we even need an irule. Where is this iRule attached? You say one website needs to not redirect to HTTPS. is that a whole FQDN or just the application pathh you specified in your sample irule?
  • Take the http:// part out of your first switch conditional. also you may want to use the glob parameter in the switch. IE switch -glob then make your condition end with a * since I assume you may have some longer paths and possible query parameters. HTTTP::uri includes query parameters.

     

    • Lucilius_223799's avatar
      Lucilius_223799
      Icon for Nimbostratus rankNimbostratus
      Thank you for the answer Brad, I changed the iRule with your recommendations. However the pages that shouldn't be redirected to https are still going to https from what I can see and are stuck in an a redirect loop. I wonder if it is something on the other side that is causing that issue though and not the iRule itself.
    • Kai_Wilke's avatar
      Kai_Wilke
      Icon for MVP rankMVP
      Please post your changed iRule, so that we can find the incorrect parts... ;-)
    • Brad_Parker's avatar
      Brad_Parker
      Icon for Cirrus rankCirrus
      Lets take one step back and see if we even need an irule. Where is this iRule attached? You say one website needs to not redirect to HTTPS. is that a whole FQDN or just the application pathh you specified in your sample irule?