Forum Discussion

murphs76_64953's avatar
murphs76_64953
Icon for Nimbostratus rankNimbostratus
Apr 28, 2014

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.

 

  1. Will the code work
  2. 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

  • 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" } }

     

    • murphs76_64953's avatar
      murphs76_64953
      Icon for Nimbostratus rankNimbostratus
      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.
    • murphs76_64953's avatar
      murphs76_64953
      Icon for Nimbostratus rankNimbostratus
      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.
  • 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