Forum Discussion

arczi45_305574's avatar
arczi45_305574
Icon for Nimbostratus rankNimbostratus
Jun 02, 2017

Irule redirection based on /value

Hi;

 

I have to write an irule to redirect a traffic to new URL based on special value from old URL.

 

For example:

 

I have this URL https://website.com/otcsEN/livelink.exe/Open/162269 , at the end is the string with changeable length. It could be 3 or 5, 7 etc. long.

 

The new URL is https://website2.com/_layouts/15/sharepoint.aspx?q=IDMSObject%3A162269&v=search, where the string 162269 have to be after %3A pattern and before & sign.

 

How can I do this? It is possible to put a value using $variable?

 

Thank you for help

 

2 Replies

  • Hi,

     

    you can use this code:

     

    when HTTP_REQUEST {
        if {[scan $uri "/otcsEN/livelink.exe/Open/%d" id] && [string length $id] > 2 && [expr {([string length $id] % 2) != 0}]} {
            HTTP::respond 302 Location " https://website2.com/_layouts/15/sharepoint.aspx?q=IDMSObject%3A${id}&v=search"
        }
    }

    I configured to filter id with odd length greater than 2 (3, 5, 7, etc). the scan check the ID contains only numbers.

     

  • Or something like this, which also takes into account the hostname.

    when HTTP_REQUEST {
        if { ([HTTP::host] equals "website.com") && ([scan [HTTP::uri] {/otcsEN/livelink.exe/Open/%s} string1  ] == 1) } {
            HTTP::redirect "https://website2.com/_layouts/15/sharepoint.aspx?q=IDMSObject%3A${string1}&v=search"
        }
    }