Forum Discussion

George_72275's avatar
George_72275
Icon for Nimbostratus rankNimbostratus
Jun 08, 2012

How to mask URL

Hi there,

 

 

I'm new to iRules and trying to come up with a solution here and hoping someone can help. I have two URLs:

 

 

1) http://www.abc.com/join

 

2) http://www.abc.com/join/events

 

 

I would like the 2nd one to stay http://www.abc.com/join/events in the URL bar when the user types it but redirect behind the scenes to http://www.abc.com/join

 

 

Is that possible?

 

 

Thanks,

 

George

 

  • Richard__Harlan's avatar
    Richard__Harlan
    Historic F5 Account
    The following should work for you

     

     

    when HTTP_REQUEST {

     

    if { [HTTP::uri] equals "/join/events" } {

     

    HTTP::uri "/join"

     

    }

     

    }
  • Unfortunately that did not work as I receive the following 404 error:

     

     

    HTTP Status 404 - /join/events/

     

    --------------------------------------------------------------------------------

     

    type Status report

     

    message /join/events/

     

    description The requested resource (/join/events/) is not available.

     

     

  • That's because the iRule is comparing the string "/join/events" and you passed in "/join/events/".

    Something like this should work

    when HTTP_REQUEST { 
      if { [HTTP::uri] equals "/join/events/" } { 
        HTTP::uri "/join" 
      } 
     }

    But, that would ONLY match a url of "/join/events/". "/join/events", "/Join/Events/", etc would not match.

    You could also use a "starts_with" to compare like this

    when HTTP_REQUEST { 
      if { [HTTP::uri] starts_with "/join/events" } { 
        HTTP::uri "/join" 
      } 
     }

    That would match "/join/events" and "/join/events/" but it would also match on "/join/eventsFOOBAR" or anything else after events in the URI.

    If you want to have more options in your comparisons, I'd use a switch statement with the "string tolower" on the URI.

    when HTTP_REQUEST {
      switch -glob [string tolower [HTTP::uri]] {
        "/join/events" -
        "/join/events/" {
          HTTP::uri "/join"
        }
      }
    }

    Lots of options, it really depends on your app logic how complex you want to go with the comparison.

    -Joe

  • Many thanks Joe!

     

     

    The switch statement with the "string tolower" did it. And now I know that much more about iRules. :)

     

     

    Thanks,

     

    George
  • The customer has now changed the requirements.

     

     

    1) http://www.abc.com/join

     

    2) http://www.abc.com/join/events

     

     

    They would like the 2nd one to stay http://www.abc.com/join/events in the URL bar when the user types it but redirect behind the scenes to a different server entirely: http://www.xyz.com/join

     

     

    What is the proper command string to make that work unbenownst to the end user?