Forum Discussion

Stuart_Feathers's avatar
Stuart_Feathers
Icon for Nimbostratus rankNimbostratus
Sep 28, 2012

Redirect with multiple conditions

I am doing a HTTPS redirect for all of the sites at my domain. I need to make an exclusion for 2 sites so that they can be access via HTTP.

 

 

For example, any traffic to http://www.abc.com is redirected to https://www.abc.com. I would like requests to http://www.abc.com/site1 and http://www.abc.com/site2 to be allowed to go to the HTTP site while all other traffic is redirected to HTTPS.

 

I've attempted to do this with the following iRule, but it is not working. Any assistance would be greatly apreciated.

 

Thanks!

 

 

when HTTP_REQUEST {

 

if { not ([string tolower [HTTP::uri]] starts_with "/site1") } {

 

HTTP::respond 301 Location "https://www.abc.com[HTTP::uri]"

 

}

 

elseif { not ([string tolower [HTTP::uri]] starts_with "/site2") } {

 

HTTP::respond 301 Location "https://www.abc.com[HTTP::uri]"

 

}

 

}

 

5 Replies

  • Firstly, remove the nots! I think perhaps also enclose Location in quotes so it's "Location". Let me know how you get on.
  • So, like this, I don't think the curved brackets are needed either btw;

    when HTTP_REQUEST {
    if { [string tolower [HTTP::uri]] starts_with "/site1" } {
        HTTP::respond 301 Location "https://www.abc.com[HTTP::uri]"
      }
    elseif { [string tolower [HTTP::uri]] starts_with "/site2" } {
        HTTP::respond 301 Location "https://www.abc.com[HTTP::uri]"
      }
    } 
  • I have also tried the following iRule which doesn't seem to work either.

     

     

    when HTTP_REQUEST {

     

    if { not ([string tolower [HTTP::uri]] starts_with "/site1") || ([string tolower [HTTP::uri]] starts_with "/site2") } {

     

    HTTP::respond 301 Location "https://www.abc.com[HTTP::uri]"

     

    }

     

    }
  • Thank you for the reply What Lies Beneath.

     

     

    Before I saw your reply I figured out the problem. I was able to get it to work by using the following code. Again, THANKS!!

     

     

    when HTTP_REQUEST {

     

    if { not (([string tolower [HTTP::uri]] starts_with "/site1") || ([string tolower [HTTP::uri]] starts_with "/site2")) } {

     

    HTTP::respond 301 Location "https://www.abc.com[HTTP::uri]"

     

    }

     

    }