Forum Discussion

Jay_41075's avatar
Jay_41075
Icon for Nimbostratus rankNimbostratus
Aug 19, 2012

iRule Errors

Hello all.. Can you please take a look at the below iRule and see why the BIGIP is giving the below errors?

 

 

when HTTP_REQUEST {

 

 

First step is to see if the HTTP requested Hostname 'Exactly' matches class vanityurls

 

This class file contains hostnames and specific http request strings as values

 

 

if { not ([string tolower [HTTP::host]] equals [www.hallmark.com||hallmark.com]) }

 

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

 

if {$vanityuri ne ""} {

 

HTTP::redirect 301 "$vanityuri"

 

unset vanityuri

 

}

 

else { HTTP::redirect 301 http://www.hallmark.com/ }

 

}

 

Second step is to see if the HTTP requested 'Exactly' matches class queryurls

 

The query needs to be appended to the redirect

 

set queryyuri [class match -value [string tolower [HTTP::path]] equals queryurls]

 

if {$queryuri ne ""} {

 

HTTP::redirect 301 "$queryuri[HTTP::query]"

 

unset queryuri

 

}

 

Third step is to see if the HTTP requested URI 'Exactly' matches class exacturls

 

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

 

if {$exacturi ne ""} {

 

HTTP::redirect 301 "$exacturi"

 

unset exacturi

 

}

 

Fourth step is to see if the HTTP requested URI 'Starts with' class starturls

 

This step only gets executed if an 'Exact' Match and 'Contains' Match was not found

 

set starturi [class match -value [string tolower [HTTP::path]] starts_with startturls]

 

if {$starturi ne ""} {

 

HTTP::redirect 301 "$starturi"

 

unset startturi

 

}

 

Fifth step is to see if the HTTP requested URI 'Contains' matches class containsurls

 

This step only gets executed if an Exact Match was not found

 

set containturi [class match -value [string tolower [HTTP::path]] contains containurls]

 

if {$containuri ne ""} {

 

HTTP::redirect 301 "$containuri"

 

unset containuri

 

}

 

}

 

 

-------------

 

 

iRule error 01070151:3: Rule [SRD-Redirect] error:

 

line 6: [undefined procedure: www.hallmark.com||hallmark.com] [www.hallmark.com||hallmark.com] line 6: [missing a script after "if"] [ ]

 

line 7: [undefined procedure: set vanityuri [class match -value [string tolower [HTTP::host]] equals vanityurls] if {$vanityuri ne ""} { HTTP::redirect 301 "$vanityuri" unset vanityuri } else { HTTP::redirect 301 http://www.hallmark.com/ } ] [{ set vanityuri [class match -value [string tolower [HTTP::host]] equals vanityurls] if {$vanityuri ne ""} { HTTP::redirect 301 "$vanityuri" unset vanityuri } else { HTTP::redirect 301 http://www.hallmark.com/ } }]

 

line 16: [can't find value_list] [class match -value [string tolower [HTTP::path]] equals queryurls]

 

line 18: [wrong args] [HTTP::redirect 301 "$queryuri[HTTP::query]"] line 22: [can't find value_list] [class match -value [string tolower [HTTP::path]] equals exacturls]

 

line 24: [wrong

 

 

Thanks,

 

Jay.

 

1 Reply

  • 1. square brackets, e.g. [www.hallmark.com||hallmark.com], evaluates of content as a command.

    iRules Optimization 101 - 04 - Delimiters: Braces, Brackets, Quotes and more by Deb

    https://devcentral.f5.com/Tutorials/TechTips/tabid/63/articleType/ArticleView/articleId/120/iRules-Optimization-101--04--Delimiters-Braces-Brackets-Quotes-and-more.aspx

    2. HTTP::redirect uses 302. If you want 301, you have to use HTTP::respond instead.

    HTTP::respond wiki

    https://devcentral.f5.com/wiki/irules.HTTP__respond.ashx

    3. since local variable will be gone after closing connection, unset may be omitted.

    can you try this irule?

    [root@ve10:Active] config  b rule myrule list
    rule myrule {
       when HTTP_REQUEST {
       set host [string tolower [HTTP::host]]
       if { not ($host equals "www.hallmark.com" or $host equals "hallmark.com") } {
          set vanityuri [class match -value [string tolower [HTTP::host]] equals vanityurls]
          if {$vanityuri ne ""} {
             HTTP::respond 301 Location "$vanityuri"
          } else {
             HTTP::respond 301 Location "http://www.hallmark.com/"
          }
       }
    
       set queryyuri [class match -value [string tolower [HTTP::path]] equals queryurls]
       if {$queryuri ne ""} {
          HTTP::respond 301 Location "$queryuri[HTTP::query]"
       }
    
       set exacturi [class match -value [string tolower [HTTP::path]] equals exacturls]
       if {$exacturi ne ""} {
          HTTP::respond 301 Location "$exacturi"
       }
    
       set starturi [class match -value [string tolower [HTTP::path]] starts_with startturls]
       if {$starturi ne ""} {
          HTTP::respond 301 Location "$starturi"
       }
    
       set containturi [class match -value [string tolower [HTTP::path]] contains containurls]
       if {$containuri ne ""} {
          HTTP::respond 301 Location "$containuri"
       }
    }
    }