Forum Discussion

uvotguy_122534's avatar
uvotguy_122534
Icon for Nimbostratus rankNimbostratus
Jul 14, 2013

How to modify a query string

Hello, I am new to the F5 and iRules, so I took a stab at writing a rule to modify part of a query string. In this case, I was trying to remove the port number from a hostname embedded in a query string. The rule runs with no error, as I can see in the log file, but the query string is unmodified.

 

Thanks in advance for helping a newbie.

 

when HTTP_REQUEST {

 

if {[HTTP::query] contains "mysite.something.com:8081"} {

 

log local0. "Query String is [HTTP::query]"

 

HTTP::query [string map { "mysite.something.com:8081" "mysite.something.com" } [HTTP::query]]

 

log local0. "Query String is now [HTTP::query]"

 

}

 

}

 

2 Replies

  • The HTTP::query command only reads. It does not set. To get around this, one possible solution is to use the HTTP::uri command instead. The query string will be part of the URI, so as long as that string doesn't appear in the path before the query string it should work for you.

    
    HTTP::uri [string map { "mysite.something.com:8081" "mysite.something.com" } [HTTP::uri]]
    

  • Thanks Kevin,

     

    That did the trick. I wrote to the author of the document I was reading (about HTTP::query) and asked him to correct it.

     

    - uvotguy