Forum Discussion

pmaubo3_109863's avatar
pmaubo3_109863
Icon for Nimbostratus rankNimbostratus
Jul 20, 2012

Using Class for uri and url redirects

We currently have a URL where they want a uri redirect which is fine. Also, the want to use a uri to invoke a URL redirect. The issue is, if we just keep adding single irules in, it gets ugly and is not effective. So I am working on a single irule that will

 

 

1. Take a uri to a page they want it to land on.

 

2. Take a uri has been used in the past and is not used anymore, so they want to have that uri redirect back to the main page.

 

 

Now... we want to use the Class so we can simply add keywords and also a class for redirects to whatever site they want.

 

 

Below, this irule works but I do not want to actually have the redirect URL in it but a variable to get the info from a class. Can anyone take a look and see if there is a better way?

 

Thanks in advance

 

 

universal_uri_url_irule

 

[Part 1]

 

when HTTP_REQUEST {

 

Class match if the vanity URI should be redirected back to www.default.com

 

if {[class match [string tolower [HTTP::uri]] equals vanity_redirect_root_www]}{

 

HTTP::redirect "https://www.default.com"

 

 

Class for this = keyword in this class determines that it will go to www.default.com

 

 

[Part 2]

 

}

 

Class match if the vanity URI should be redirectd to another site

 

if {[class match [string tolower [HTTP::uri]] equals vanity_redirect_diff_domain]}{

 

HTTP::redirect "https://diff.domain.com"

 

}

 

}

 

 

Once again. on Part 2 I do not want to list the url directly but grab it from a class

 

4 Replies

  • what about this one?

    [root@ve10:Active] config  b virtual bar list
    virtual bar {
       snat automap
       destination 172.28.19.79:80
       ip protocol 6
       rules myrule
       profiles {
          http {}
          tcp {}
       }
    }
    [root@ve10:Active] config  b rule myrule list
    rule myrule {
       when HTTP_REQUEST {
       if {[class match -- [string tolower [HTTP::uri]] starts_with url_class]} {
          HTTP::redirect [class match -value [string tolower [HTTP::uri]] starts_with url_class]
       } else {
           default pool
          pool foo
       }
    }
    }
    [root@ve10:Active] config  b class url_class list
    class url_class {
       {
          "/bring_me_to_google" { "http://www.google.com" }
          "/bring_me_to_yahoo" { "http://www.yahoo.com" }
       }
    }
    
    [root@ve10:Active] config  curl -I http://172.28.19.79/bring_me_to_google/something
    HTTP/1.0 302 Found
    Location: http://www.google.com
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    [root@ve10:Active] config  curl -I http://172.28.19.79/bring_me_to_yahoo/something
    HTTP/1.0 302 Found
    Location: http://www.yahoo.com
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    
  • Thanks. That works just fine. I really don't need the else to a pool but will try it to go to the default homepage.

     

    I'm also looking for a redirect if any 404, etc errors show up, to throw them back to the homepage.

     

    The reason is, we have ad pages that expire and we don't want the customer to experience going to an old ad page if it was caches, and want to throw any errors to always go back. I'll try it with the homepage pool though and that probably would work.

     

  • I'm also looking for a redirect if any 404, etc errors show up, to throw them back to the homepage.have you seen an example in HTTP_RESPONSE event wiki? hope it is useful.

     

     

    HTTP_RESPONSE event wiki

     

    https://devcentral.f5.com/wiki/irules.HTTP_RESPONSE.ashx
  • Hi,

     

     

    Yes that is what I was looking for. Not sure if I can put it all in one irule but I'm checking.

     

    Thanks again