Forum Discussion
Mobile redirect iRule :uri "/groupon" to m.site.com/19550
Hello Network Engineers asked to be overnight developers :),
I am asked to write a redirect iRule.
Here is what I came up with -->
when HTTP_REQUEST { if { [string tolower [HTTP::uri]] starts_with "/groupon" } { HTTP::redirect "m.site.com/1231" } if { [string tolower [HTTP::uri]] starts_with "/shoprunner" } { HTTP::redirect "m.site.com/1232" } if { [string tolower [HTTP::uri]] starts_with "/hilton" } { HTTP::redirect "m.site.com/1233" } }
This is a small set. The full iRule would be hundreds of redirects in one irule for one VIP.
- Will the code work
- Should it be done (i know it shouldn't but so far have not given an argument that swayed the business).
Any help would be greatly appreciated.
Thanks in advance,
-Greg
6 Replies
- murphs76_64953
Nimbostratus
Slight modification to my posted code. subsequent if statements are elseif
when HTTP_REQUEST { if { [string tolower [HTTP::uri]] starts_with "/groupon" } { HTTP::redirect "m.site.com/1231" } elseif { [string tolower [HTTP::uri]] starts_with "/shoprunner" } { HTTP::redirect "m.site.com/1232" } esleif { [string tolower [HTTP::uri]] starts_with "/hilton" } { HTTP::redirect "m.site.com/1233" } }
- nitass_89166
Noctilucent
i think it would be simpler to use data group for matching and redirection.
e.g.
Single I-rule with 1000+ URI Redirect
https://devcentral.f5.com/questions/single-i-rule-with-1000-uri-redirect- murphs76_64953
Nimbostratus
Thanks for the comment nitass. That is a great article. I don't think it will work in this situation. That article replaces one uri with another. The requirement is to redirect to a different site bases upon the uri and rewrite the url and uri. original site is "site.com" the new site is "m.site.com". I should have made that clear in the original post.
- nitass
Employee
i think it would be simpler to use data group for matching and redirection.
e.g.
Single I-rule with 1000+ URI Redirect
https://devcentral.f5.com/questions/single-i-rule-with-1000-uri-redirect- murphs76_64953
Nimbostratus
Thanks for the comment nitass. That is a great article. I don't think it will work in this situation. That article replaces one uri with another. The requirement is to redirect to a different site bases upon the uri and rewrite the url and uri. original site is "site.com" the new site is "m.site.com". I should have made that clear in the original post.
- nitass
Employee
I don't think it will work in this situation.
why not?
e.g.
config [root@ve11a:Active:In Sync] config tmsh list ltm virtual bar ltm virtual bar { destination 172.28.24.10:80 ip-protocol tcp mask 255.255.255.255 profiles { http { } tcp { } } rules { qux } source 0.0.0.0/0 vs-index 9 } [root@ve11a:Active:In Sync] config tmsh list ltm rule qux ltm rule qux { when HTTP_REQUEST { if { [class match -- [string tolower [HTTP::path]] starts_with redirect_class] } { HTTP::redirect "http://[class match -value [string tolower [HTTP::path]] starts_with redirect_class]" } } } [root@ve11a:Active:In Sync] config tmsh list ltm data-group internal redirect_class ltm data-group internal redirect_class { records { /groupon { data m.site.com/1231 } /hilton { data m.site.com/1233 } /shoprunner { data m.site.com/1232 } } type string } test [root@ve11a:Active:In Sync] config curl -I http://site.com/groupon/something HTTP/1.0 302 Found Location: http://m.site.com/1231 Server: BigIP Connection: Keep-Alive Content-Length: 0 [root@ve11a:Active:In Sync] config curl -I http://site.com/shoprunner/something HTTP/1.0 302 Found Location: http://m.site.com/1232 Server: BigIP Connection: Keep-Alive Content-Length: 0 [root@ve11a:Active:In Sync] config curl -I http://site.com/hilton/something HTTP/1.0 302 Found Location: http://m.site.com/1233 Server: BigIP Connection: Keep-Alive Content-Length: 0
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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