Forum Discussion
Ruchir_76829
Jan 20, 2012Nimbostratus
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/ ...
hooleylist
Jan 20, 2012Cirrostratus
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
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects