Forum Discussion
Jakov_40007
Nimbostratus
Mar 26, 2010HTTP::path and HTTP::query question
I am new to iRules and having difficulty writing a rule that will rewrite a request from the client to a server by replacing the 'path' but will still retain the query string that follows. I have written the following rule, and it seems to be working fine for rewriting the path, but in the process the query string gets lost and never makes it to the server.
when HTTP_REQUEST {
if { [string tolower [http::host]] equals "www.abc.com" } {
if { [http::path] equals "/"} {
http::path "/en-CA/default.htm"
return
}
}
In this case, if I browse to http://www.abc.com/?xyz=8 what is reaching the server is http://www.abc.com/en-CA/default.htm, but the query (in this case 'xyz=8') gets stripped off. What I need it to do is send http://www.abc.com/en-CA/default.htm?xyz=8 or whaever the query value may be.
Thanks!
- hoolio
Cirrostratus
It looks like your rule should work to rewrite just the path (and preserve the query string). Can you add some logging to check?when HTTP_REQUEST { log local0. "[IP::client_addr]:[TCP::client_port]: Original [HTTP::method] request to [HTTP::host][HTTP::uri]\ with path [HTTP::path] and query [HTTP::query]" if { [string tolower [HTTP::host]] equals "www.abc.com" } { if { [HTTP::path] equals "/"} { HTTP::path "/en-CA/default.htm" } } } when HTTP_REQUEST priority 501 { log local0. "[IP::client_addr]:[TCP::client_port]: Current: [HTTP::method] request to [HTTP::host][HTTP::uri]\ with path [HTTP::path] and query [HTTP::query]" }
- Jakov_40007
Nimbostratus
Hi Aaron, - Jakov_40007
Nimbostratus
I added the log both inside and outside the rule, and here is what I get both inside and outside the rule now. Not sure why it came back as blank query before. - hoolio
Cirrostratus
What does the second log line show? ie, is the change actually made to the path? - Jakov_40007
Nimbostratus
The second log shows no query: - hoolio
Cirrostratus
That seems like a bug. HTTP::path should only return or set the path in the URI without retrieving or modifying the query string. You could work around this using HTTP::uri instead:when HTTP_REQUEST { Check if path is / if {[HTTP::path] eq "/"}{ Parse the URI into the path and query scan [HTTP::uri] {%[^?]?%s} path query Check if there was a query if {[info exists query]}{ Update path, preserving query HTTP::uri "/en-CA/default.htm?$query" } else { Update path without query HTTP::uri "/en-CA/default.htm" } } }
- Jakov_40007
Nimbostratus
Hi Aaron, - hoolio
Cirrostratus
Hi Jakov, - Jakov_40007
Nimbostratus
Hi Aaron,
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects