Forum Discussion

Ruchir_76829's avatar
Ruchir_76829
Icon for Nimbostratus rankNimbostratus
Jan 20, 2012

IRules mobile redirects help

Hello Everyone,

 

 

I am stuck with particular type of redirects, what I need to do is ..

 

 

 

say a user request

 

abc.com/acd/dder/dr1-dc2-1245/ or http://abc.com/adv/dcb/34567/

 

from mobile device, so I want to take last portions numrics out

 

 

 

like 1245 in first URL and 34567 in second URL, and redirect it to something like site?gid=1245 or 34567

 

 

 

last digits are not limited with only 4 or 6 it can be abything, just numbers after - or after / .. I am unable to find out a way to do it ..

 

and if last digit is not numbers then just redirect to m.site.com

 

 

 

Please let me know if anyone can help out with it ..

 

 

 

Regards,

 

Ruchir

 

  • Hi Ruchir,

     

     

    Can you provide a few more examples of the URIs you want to redirect to the mobile site?

     

     

    If the digits are present are they always in the third subdirectory of the path? Is it always a format like // // /letters/ /letters/? Or are there other formats?

     

     

    Aaron
  • there can be many format, what we need to capture is digits from last and break point is either - or /

     

     

    so if URI end is /234567/ - then ID = 234567

     

    if URI last is /ar1-br2-cr3-3456/ then ID=3456

     

     

  • So it's always the last subdirectory that you want to parse? And are the digits always on their own // or // or following a hyphen like this /AAA-AAA-AAA-/ or /AAA-AAA-AAA-/?

    If so you could try something like this example. Note that I haven't fully tested it. So if you see any issues can you reply back with the debug from /var/log/ltm?

    
    when HTTP_REQUEST {
    
     Get the index of the last URI directory
    set depth [URI::path [HTTP::uri] depth]
    
     Parse the last directory in the path
    set last_dir [URI::path [HTTP::uri] $depth $depth]
    
     Parse everything after the last hyphen in the last directory
    set digits [string trimleft [string range $last_dir [expr {[string last - $last_dir]}] end-1] -/]
    
    log local0. "URI=[HTTP::uri], \$depth=$depth, \$last_dir=$last_dir, \$digits=$digits"
    
     Check if we parsed 4 or 6 digits
    switch $digits {
    [0-9][0-9][0-9][0-9] -
    [0-9][0-9][0-9][0-9][0-9][0-9] {
     Found 4 or 6 digits, send a redirect
    HTTP::redirect "http://m.site.com/test/?gid=$digits"
    }
    }
    }
    

    It would be more efficient if you could only perform this URI parsing for specific requests that might have the GID in the path. Do the requests always start with a standard path? Or is there another way that you could limit when you check for the 4 or 6 digits?

    Aaron