Forum Discussion

Bciesz_171056's avatar
Jun 01, 2017

iRule for URI/string manipulation

Hi, I need to perform some complex redirections on a VS due to sharepoint migration. Users are reaching my VS using an URL with a specific variable included, like f.ex.:

 

 

I need to extract the object ID (1234 obviously) and push it in new URL:

 

so the objid variable is trasnferred to q variable with OBJECT%1A inserted in the beggining;

 

Also a legacy URL might appear: where 1234 should be treated same as objid

 

Another variation might be a substitution from this: to

 

still I'm not quite sure how to handle such string manipulation in iRule, especially that the lenght of variable q might differ from query to query, and when it is provided in text we can't be sure what it will be exactly...

 

Any help appreciated :)

 

thanks

 

1 Reply

  • Hi,

    you can try with this irule:

    when HTTP_REQUEST {
        switch -glob -- [string tolower [HTTP::path]] {
            "/api.dll" {
                set objid [URI::query [HTTP::uri] objid]
                HTTP::respond 301 Location "http://www.newsite.com/sharepoint.aspx?q=OBJECT%1A${objid}&v=look"
            }
            "/api.dll/[0-9][0-9][0-9][0-9]" {
                set objid [URI::basename [HTTP::uri]]
                HTTP::respond 301 Location "http://www.newsite.com/sharepoint.aspx?q=OBJECT%1A${objid}&v=look"
            }
            "/api.dll/*" {
                set objid [URI::basename [HTTP::uri]]
                HTTP::respond 301 Location "http://www.newsite.com/sharepoint.aspc?q=eLearning?v=look"
            }
        }
    
    }