Forum Discussion

Ravi_Kakran's avatar
Ravi_Kakran
Icon for Nimbostratus rankNimbostratus
Jun 20, 2019

IRule condtion for one mor more slashes in URL

Hi,

 

I am working on website where we use F5 server to set some irules for application URLs. Recently we noticed that application URL is breaking if we put more than one forward slashes (/) at the end of the domain URL. for example - https://www.cna.com//

 

Currently we have one irule set for controlling URL without any slash at very end - https://www.cna.com with EQUALS operator.

 

We tried a lot to find our a condition (for example contains, starts_with. ends_with, or and many more) to deal with more than one slashes at the URL.

 

Please help to find out correct condition to deal with this situation.

 

Thanks.

11 Replies

  • Though I mentioned what logic we have but find following irule setup for single slash:

     

    if { ([HTTP::uri] equals "/") } {

    HTTP::redirect "https://[HTTP::host]/web/guest/cna/home"

    #log local0. "debug0000: [IP::client_addr]:[TCP::client_port]: [HTTP::method] to [HTTP::host][HTTP::uri]"

    }

     

    We would like to know what should be the right irule of domain URL has 2 or more slashes. I have mentioned what we already tried.

     

    Please advise.

     

    Thanks.

  • JG's avatar
    JG
    Icon for Cumulonimbus rankCumulonimbus

    This should reduce all trailing slashes to one only, but I haven't tested it yet:

    when HTTP_REQUEST {
        if { [HTTP::uri] ends_with "//" } { 
            set new_uri [string trimright [HTTP::uri] '/']
            HTTP::uri "$new_uri/"
        }
        if { [HTTP::uri] equals "/" } {   
            HTTP::redirect "https://[HTTP::host]/web/guest/cna/home"
        }
    } 

    [Edited]

  • Rob2's avatar
    Rob2
    Icon for Nimbostratus rankNimbostratus

    I'm not exactly sure of your requirement but another idea and very quick to handle double // at end of URI without if constructs, string functions...

    when HTTP_REQUEST {
       # replaces // at end of URI with / if present
       HTTP::uri [regsub "\//$" [HTTP::uri] "/"] 
       HTTP::redirect "https://[HTTP::host]/web/guest/cna/home"
    }
    • Ravi_Kakran's avatar
      Ravi_Kakran
      Icon for Nimbostratus rankNimbostratus

      Hi Rob,

       

      As requested, can yo please advise what should be the right syntax for suggested irule as this rule is showing syntax error. Please do the needful... thanks.

  • Thanks JD for your suggestion!!

     

    Rob,

    Our requirement is - no matter how many slashes user put at end of domain URL, it should always redirect to application home page without any redirection. for example - https://www.cna.com// or https://www.cna.com//// and so on.

     

    We were able to achieve what is expected by using "starts_with" operator in IF condition but we got "multiple redirect" error

     

    Please advise.

     

    Thanks.

  • JG's avatar
    JG
    Icon for Cumulonimbus rankCumulonimbus

    Have you tried the irule I provided above?

  • Yes JD but did not work. It worked as same as one "/". Please advise.

     

    Rob, even we tried your suggestion we are getting syntax error. Request you to please share with proper syntax.

     

    Please do share in case of any other suggestions.

     

    Thanks.

  • JG's avatar
    JG
    Icon for Cumulonimbus rankCumulonimbus

    I have fixed an error in the irule and you can try it again.

  • JG's avatar
    JG
    Icon for Cumulonimbus rankCumulonimbus

    Or better still change it to use "HTTP::path" instead:

    when HTTP_REQUEST {
        if { [HTTP::path] ends_with "//" } {
            set new_path [string trimright [HTTP::path] '/']
            HTTP::path "$new_path/"
        }
        if { [HTTP::path] equals "/" } {  
            HTTP::redirect "https://[HTTP::host]/web/guest/cna/home"
        }
    }
    • Ravi_Kakran's avatar
      Ravi_Kakran
      Icon for Nimbostratus rankNimbostratus

      Sorry JG, even this above did not work. Error while executing scenario, screenshot attached.

       

      Please do the needful and thank you for your help.