Forum Discussion

Jangle_40463's avatar
Jangle_40463
Icon for Nimbostratus rankNimbostratus
Jun 27, 2014

Redirect Failure for iRule

I am trying to work out why my iRule fails for one specific redirect whereas everything else works.

 

Any assistance or advise would be appreciated.

 

Http://testssl.communigatormail.co.uk/Common/Images/map.gif Redirect to :https://testssl.communigatormail.co.uk/Login/Common/Images/map.gif

 

when HTTP_REQUEST { if { [HTTP::host] eq "testssl.communigatormail.co.uk" } { switch [string tolower [HTTP::path]] { "/" { HTTP::redirect "https://testssl.communigator.co.uk/login" } default { HTTP::redirect "https://testssl.communigator.co.uk/[HTTP::uri]" } } } elseif { [HTTP::host] eq "testssl.communigatormail.co.uk" } { switch -glob [string tolower [HTTP::path]] { "/Common/" { HTTP::redirect "https://testssl.communigator.co.uk[HTTP::uri]" } } } elseif { [HTTP::host] eq "testssl.communigator.co.uk" } { switch -glob [string tolower [HTTP::path]] { "/login/" - "/lz/*" { HTTP::redirect "https://testssl.communigator.co.uk[HTTP::uri]" } } } }

 

6 Replies

  • I'm guessing your check for /Common isn't working? This is because you are comparing a lowercase version of the incoming HTTP path to a string that contains a capital letter, so it'll never match. Change "/Common" to "/common" and see if that fixes your issue.

     

  • Good Afternoon Cory,

     

    I have made the change you suggested but still it refuses to redirect.

     

    Regards, Stuart

     

  • Arie's avatar
    Arie
    Icon for Altostratus rankAltostratus

    Have you checked the logic in your code? The first block in the if-statement is executed if the host equals testssl.communigator.co.uk, but it only contains the redirect of the root.

     

    The redirect for the /common/ folder is in the else-block, so the host cannot match testssl.communigator.co.uk. However, in your description you indicate that the request you want to redirect does in fact match that host.

     

  • A couple things that I noticed:

     

    1. Looks like your first 2 if...elseif statements are the same (if the test it testssl.communigator.co.uk). I'd consolidate and use a single "switch -glob"

       

    2. On you switch -glob looking at /Commons, Cory is right about checking needing to make that lowercase or it won't match, but the way you have it, it's looking for a path EXACTLY like "/common/". If you change it to "/common/*" (so it'll check that it starts with /common/ and could have something after that), that may help you out. (Not to mention if you wanted to prepend the /login/, you'd need to update the redirect to ...".co.uk/login[HTTP::uri]"

       

    Does that help at all?

     

    So the new code might look something like this:

     

    when HTTP_REQUEST { 
        if { [HTTP::host] eq "testssl.communigatormail.co.uk" } { 
            switch -glob [string tolower [HTTP::path]] { 
                "/" { 
                    HTTP::redirect "https://testssl.communigator.co.uk/login" 
                    }
                "/common/*" { 
                    HTTP::redirect "https://testssl.communigator.co.uk/login[HTTP::uri]" 
                }  
                default { 
                    HTTP::redirect "https://testssl.communigator.co.uk/[HTTP::uri]" 
                }
            } 
        } elseif { [HTTP::host] eq "testssl.communigator.co.uk" } { 
            switch -glob [string tolower [HTTP::path]] { 
                "/login/" - 
                "/lz/*" { 
                    HTTP::redirect "https://testssl.communigator.co.uk[HTTP::uri]" 
                } 
            }
        }
    }
  • Good Evening,

     

    Thank you Arie/Michael, I will work through your suggestions and advise on the outcome.

     

    Thank you for your assistance it is appreciated.

     

    Regards, Stuart

     

  • Michael J,

     

    Massive thank you for the code it worked a treat, your assistance is greatly appreciated.

     

    Thank you to all for your assistance.

     

    Regards, Stuart