Forum Discussion

anonymous_02_15's avatar
anonymous_02_15
Icon for Nimbostratus rankNimbostratus
May 31, 2014

URL re-Write

Hi ,

 

I am trying to write an irule which would rewrite the uri as below:

 

original uri https://www.ABC.com/BBB/CCC/DDDD/TK?grant_type=client_credentials --> the part after TK "could be anything"

 

re-write to https://www.ABC.com/CCC/DDDD/TK?grant_type=client_credentials

 

I have tried many irules but nothing seems to work.

 

Your support is highly appreciated.

 

6 Replies

  • nathe's avatar
    nathe
    Icon for Cirrocumulus rankCirrocumulus

    How about something like this?

    when HTTP_REQUEST {
       set uri [HTTP::uri]
       if { $uri starts_with "/BBB" } {
          HTTP::uri [string range $uri 4 end]
       }
    }
    

    See info on String here string command

  • Hi Nathan ,

     

    Thanks for your reply.

     

    I forgot to to mention that I only need /BBB be removed when it is followed by /CCC , if it is followed by anything else I dont want the re-writing to happen.

     

  • nathe's avatar
    nathe
    Icon for Cirrocumulus rankCirrocumulus

    Could we not check if it starts_with /BBB/CCC ?

     

  • Oh sorry , I misunderstood you.

     

    Yes we can.. Thank you..

     

    What does 4 mean in the irule?

     

    • nathe's avatar
      nathe
      Icon for Cirrocumulus rankCirrocumulus
      String range is creating a new URI based on the existing one but starting 4 characters in I.e. ignoring /BBB
  • Arie's avatar
    Arie
    Icon for Altostratus rankAltostratus

    Is the case (upper/lower) relevant? The current rule will only detect upper case "/BBB".