Forum Discussion

dpeterson_24304's avatar
dpeterson_24304
Icon for Nimbostratus rankNimbostratus
Sep 15, 2011

Syntax errors on match_glob?

I've got a remarkably boring rule that I'm getting a syntax error on, and I don't understand why. I've also tried string_match and am getting similar errors, but I'm just not seeing what I'm doing wrong:

 

 

On https calls, detect no www and redirect to www

 

when HTTP_REQUEST {

 

if { [HTTP::host] matches_glob "blah*.com" } {

 

HTTP::redirect "https://www.[HTTP::host][HTTP::uri]"

 

}

 

}

 

 

 

 

I get this:

 

 

 

01070151:3: Rule [BLAH_HTTPS_NO_WWW] error:

 

line 3: [parse error: PARSE syntax 91 {syntax error in expression " [HTTP::host] matches_glob "blah*.com" ": extra tokens at end of expression}] [{ [HTTP::host] matches_glob "blah*.com" }]

 

 

 

 

Basically I'm just trying to redirect a number of numbered domains (say blah1.com - blah10.com) to www.blah1.com without writing rules for each one.

 

 

 

Any thoughts?

 

4 Replies

  • The iRule looks okay. It's odd that that you're getting an error. Are you on 10.0 or higher?

     

     

    Can you try this?

     

     

    if { [HTTP::host] matches_glob {blah*.com} } {

     

     

    Aaron
  • Same error there. We're on 9.3.1.

     

     

    A switch statement works though:

     

     

     

    On https calls, detect no www and redirect to www

     

    when HTTP_REQUEST {

     

    switch -glob [HTTP::host] {

     

    "blah*.com" {

     

    HTTP::redirect "https://www.[HTTP::host][HTTP::uri]"

     

    }

     

    }

     

    }

     

     

  • matches_glob was added in 10.0.0. You could use switch -glob or string match in prior versions.

     

     

    http://www.tcl.tk/man/tcl8.4/TclCmd/string.htmM35

     

     

    Aaron
  • Ah, ok that makes sense, thanks! I did try string match and get a similar error, but switch works for this particular case.