Forum Discussion

brent112_11716's avatar
brent112_11716
Icon for Nimbostratus rankNimbostratus
May 02, 2012

Rewrite a portion of URI

Is there an easy way to re-write only a portion of the URI? Say i want to turn this.

 

 

http://sharepoint/Information Technology/Information Technology Internal/projects/11111/default.aspx

 

 

 

to

 

 

 

http://sharepoint/IT/ITI/projects/11111/default.aspx

 

 

 

I only want to re-write the "Information Technology/Information Technology Internal" to

 

"IT/ITI" and keep everything after portion of the URI in place, is this even possible?

 

 

 

Thanks,

 

Brent

 

3 Replies

  • Hi,

     

     

    If you want to simply rewrite the URI, you can do the following:

     

     

    when HTTP_REQUEST {

     

    if { [set path [findstr [HTTP::uri] "/Information Technology/Information Technology Internal" 56]] ne "" } {

     

    HTTP::uri "/IT/ITI/$path"

     

    }

     

    }

     

  • So what does your example actually do? I am not sure what the 56 and "ne" are for? Does it set the $path variable to anything after the "/Information Technology/Information Technlogy Internal" and then rewrite the URI with the "IT/ITI" and the path variable appended to it?

     

     

    Thanks for the help. I am new to irules.

     

  • The findstr command allows you to look for something within a string, then you can issue a skip count which in this case is 56. This means the variable "path" is being stored with everything after "/Information Technology/Information Technology Internal/".

     

    The HTTP::uri command then modifies what is sent to the backend server.

     

     

     

     

    The "ne" just means "not equal to", so if the set statement returns nothing, it won't execute the above HTTP::uri command.