Forum Discussion

JustCooLpOOLe's avatar
JustCooLpOOLe
Icon for Cirrocumulus rankCirrocumulus
Nov 07, 2017

Need Help with iRule

Example URL:

 

http://test.test.com/t/BA/CkA/E2I/ABqYWA/AA/MTUxMzV8aHR0cHM6Ly9wcm8ubW9uZXltYXBwcmVzcy5jb20vbS83ODM4MzM-ZW1haWw9Sk9ITiU0MDE0d2VzdGl0Lm9ubWljcm9zb2Z0LmNvbSZhPTQmbz0yNjI0JnM9NDk2MiZ1PTE3NDI5MzYmbD0xNTEzNSZyPU1DMiZ2aWQ9NDJjTGZKJmc9MA/AQ/fWN2

 

The iRule needs to be able to locate the 7th "chunk" of the URI, add a period (.) to the end of it and re-insert it back into the URI before passing it back to the pool. "Chunks" are separated by the forward slash within the URI, so in this case, the 7th "chunk" begins with "/MTUxMzV8...". I'm not sure if this can be done with regex within an iRule but thought I would throw it out there to see if anyone had any thoughts on this.

 

Any help is greatly appreciated!

 

  • regex should be avoided at all cost. A simple string map would be appropriate here. Just in the tcl shell, this is accomplished with an lindex/split (you can use getfield in an iRule which is just an lindex/split shortcut):

    % set x "/t/BA/CkA/E2I/ABqYWA/AA/MTUxMzV8aHR0cHM6Ly9wcm8ubW9uZXltYXBwcmVzcy5jb20vbS83ODM4MzM-ZW1haWw9Sk9ITiU0MDE0d2VzdGl0Lm9ubWljcm9zb2Z0LmNvbSZhPTQmbz0yNjI0JnM9NDk2MiZ1PTE3NDI5MzYmbD0xNTEzNSZyPU1DMiZ2aWQ9NDJjTGZKJmc9MA/AQ/fWN2"
    
    /t/BA/CkA/E2I/ABqYWA/AA/MTUxMzV8aHR0cHM6Ly9wcm8ubW9uZXltYXBwcmVzcy5jb20vbS83ODM4MzM-ZW1haWw9Sk9ITiU0MDE0d2VzdGl0Lm9ubWljcm9zb2Z0LmNvbSZhPTQmbz0yNjI0JnM9NDk2MiZ1PTE3NDI5MzYmbD0xNTEzNSZyPU1DMiZ2aWQ9NDJjTGZKJmc9MA/AQ/fWN2
    
    % set y [lindex [split $x /] 7]
    
    MTUxMzV8aHR0cHM6Ly9wcm8ubW9uZXltYXBwcmVzcy5jb20vbS83ODM4MzM-ZW1haWw9Sk9ITiU0MDE0d2VzdGl0Lm9ubWljcm9zb2Z0LmNvbSZhPTQmbz0yNjI0JnM9NDk2MiZ1PTE3NDI5MzYmbD0xNTEzNSZyPU1DMiZ2aWQ9NDJjTGZKJmc9MA
    
    % string map [list ${y} ${y}.] $x
    
    /t/BA/CkA/E2I/ABqYWA/AA/MTUxMzV8aHR0cHM6Ly9wcm8ubW9uZXltYXBwcmVzcy5jb20vbS83ODM4MzM-ZW1haWw9Sk9ITiU0MDE0d2VzdGl0Lm9ubWljcm9zb2Z0LmNvbSZhPTQmbz0yNjI0JnM9NDk2MiZ1PTE3NDI5MzYmbD0xNTEzNSZyPU1DMiZ2aWQ9NDJjTGZKJmc9MA./AQ/fWN2
    

    In the iRule, it will consolidate to something like this:

    set uri_chunk [getfield [HTTP::uri] / 8]
    string map [list ${uri_chunk} ${uri_chunk}.] [HTTP::uri]