Forum Discussion

Dan_85248's avatar
Dan_85248
Icon for Nimbostratus rankNimbostratus
Sep 04, 2012

Simple redirect question

So initial URL would be something like

 

 

http://www.hostname.com/export/text1/test2.csv

 

 

 

Redirect to http://s3.amazonaws.com/text1/test2.csv

 

Basically it would need to redirect the same thing to amazon instead of our web site and exclude the /export and do this for any URL that has /export*

 

 

Someone mentioned that I could do something like the following:

 

 

[string range [HTTP::uri] [string length "/export/”] end]

 

But I'm not quite sure on the syntax of how to put this into my larger redirect rule that we are using based on class files of exact, contains, starts with, etc. so for example that rule looks something like the below and too new at iRules to know how the syntax would work for the above requirements.

 

 

snipit of my current rule and not sure on syntax and method to add the additional logic here. (Thank you in advance)

 

rule SRD-Redirect {

 

when RULE_INIT {

 

set static::DEBUG 1

 

if {$static::DEBUG} {log local0. "RULE_INIT>>"}

 

}

 

when HTTP_REQUEST {

 

set host [string tolower [HTTP::host]]

 

if { not ($host equals "prod.site.com" or $host equals "site.com") } {

 

set vanityuri [class match -value [string tolower [HTTP::host]] equals vanityurls]

 

if {$vanityuri ne ""} {

 

log local0. "VANITY Current HTTP Host: [HTTP::host][HTTP::path] $vanityuri"

 

HTTP::respond 301 Location "$vanityuri"

 

return

 

}

 

set exacturi [class match -value [string tolower [HTTP::uri]] equals exacturls]

 

if {$exacturi ne ""} {

 

log local0. "EXACT Current HTTP Host: [HTTP::host][HTTP::uri] $exacturi"

 

HTTP::respond 301 Location "$exacturi"

 

return

 

}

 

 

 

  • e.g.

    [root@ve10:Active] config  b virtual bar list
    virtual bar {
       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 {[HTTP::host] eq "www.hostname.com" and \
          [HTTP::uri] contains "/export/"} {
          HTTP::redirect "http://s3.amazonaws.com[string map {/export/ /} [HTTP::uri]]"
       }
    }
    }
    [root@ve10:Active] config  curl -I http://172.28.19.79/export/text1/test2.csv -H "Host: www.hostname.com"
    HTTP/1.0 302 Found
    Location: http://s3.amazonaws.com/text1/test2.csv
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0