Forum Discussion

Mary_G_147416's avatar
Mary_G_147416
Icon for Nimbostratus rankNimbostratus
Aug 03, 2017

http to https redirect irule with an exception

I'm tasked with changing a http redirect irule to add an exception, if the url includes a certain word "investor-relations", then do not redierct to https, for everything else, redirect to https.

 

the current irule for just the http to https redirect is:

 

when HTTP_REQUEST {

 

HTTP::respond 301 Location "https://[getfield [HTTP::host] ":" 1][HTTP::uri]"

 

}

 

I tried changing it to below (meaning if it doesn't equal that url, then redirect to https)

 

when HTTP_REQUEST {

 

if { ![HTTP::uri] equals "/about-*****/investor-relations" } {

 

HTTP::respond 301 Location "https://[getfield [HTTP::host] ":" 1][HTTP::uri]"

 

}

 

}

 

but it does not work.

 

As I could not keep trying different thing on production, I received a test vip and environment to apply a similar iRule and test with curl command but so far nothing works.

 

I tried changing the iRule and add "else" but that breaks the vip.

 

when HTTP_REQUEST {

 

if { ![HTTP::uri] ends_with "postinfo.html" } {

 

HTTP::respond 301 Location "http://[getfield [HTTP::host] ":" 1][HTTP::uri]"

 

} else {

 

HTTP::respond 301 Location "https://[getfield [HTTP::host] ":" 1][HTTP::uri]"

 

}

 

}

 

Can you please help me with what I might be missing?

 

  • The "!" (not) operation needs to negate the statement "uri equals something". Put the statement in parentheses with the "!" outside as follows: { !([HTTP::uri] equals "/about-*****/investor-relations") }

     

    Also, try contains "investor-relations"

     

    OR

     

    matches_glob "/about-*/investor-relations"

     

    "equals" expects the literal "*" character

     

  • Jeff_Maddox_394's avatar
    Jeff_Maddox_394
    Historic F5 Account

    The "!" (not) operation needs to negate the statement "uri equals something". Put the statement in parentheses with the "!" outside as follows: { !([HTTP::uri] equals "/about-*****/investor-relations") }

     

    Also, try contains "investor-relations"

     

    OR

     

    matches_glob "/about-*/investor-relations"

     

    "equals" expects the literal "*" character

     

    • Mary_G_147416's avatar
      Mary_G_147416
      Icon for Nimbostratus rankNimbostratus

      Hi Jeff, Thanks for the help. I tested adding the parentheses with the test vip and what you suggested works! I'm waiting on approvals to try it on the production vip again, will update as soon as that works too.

       

      have a good day!