Forum Discussion
Fotios_30046
Nimbostratus
Sep 14, 2007Static URI Rewrites
Our website search functionality has gone through some heavy modifications recently and in doing so, the url's have been completely rewritten.
To give you a better understanding of whats going on, I'll list the old way and the new way.
www.site.com/common/search/searchcombined.asp?category=XXYYZZ
www.site.com/common/search/searchresult.aspx?categoryid=AABBCC
Additionally, we have a static list of mappings between XXYYZZ and AABBCC that I can populate into a list.
I've gone through the boards and put together the following iRule, but its not working.
class CategoryID
{
"LIGHTING 26"
"BEDROOM 30"
}
when HTTP_REQUEST
{
if {[HTTP::path] == "/searchcombined.asp" }
{
set qstring [HTTP::query]
set CategoryID1 [findstr "category=" [HTTP::query] 7 "&"]
if {$CategoryID1 != ""}
{
set CategoryID2 [findclass $CategoryID1 $::CategoryIDs " "]
if {$CategoryID2 != ""}
{
set qstring [string map [list $CategoryID1 $CategoryID2] $qstring]
}
}
HTTP::respond 301 Location "http://[HTTP::host]/common/search/SearchResult.aspx$qstring"
}
}
Any help or suggestions would be great.
- You were really really close. There are a couple of issues with your iRule...Findstr usage
findstr
findstr
Data Group Namingwhen HTTP_REQUEST { if {[HTTP::path] == "/searchcombined.asp" } { set CategoryID1 [findstr [HTTP::query] "category=" 9 "&"] if {$CategoryID1 != ""} { set CategoryID2 [findclass $CategoryID1 $::CategoryIDs " "] if {$CategoryID2 != ""} { set qstring [string map [list $CategoryID1 $CategoryID2] $qstring] } } HTTP::respond 301 Location "http://[HTTP::host]/common/search/SearchResult.aspx?$qstring" } }
- Fotios_30046
Nimbostratus
Joe, - If you are using log statements and they are not showing up in your /var/log/ltm file, then something is wrong with your configuration. Try putting this in your iRule
... when HTTP_REQUEST { log local0. "HTTP Request for URI: [HTTP::uri]" ... }
- Fotios_30046
Nimbostratus
Joe,when HTTP_REQUEST { if {[HTTP::path] == "/SearchCombined.asp"} { set CategoryID1 [findstr [HTTP::query] "category=" 9 "&"] log local0. "set command = >$CategoryID1<" if {$CategoryID1 != ""} { set CategoryID2 [findclass $CategoryID1 $::CategoryIDs " "] log local0. "set command = >$CategoryID2<" if {$CategoryID2 != ""} { set qstring [string map [list $CategoryID1 $CategoryID2] $qstring] log local0. "set command = >$qstring<" } } HTTP::respond 301 Location "http://[HTTP::host]/common/search/SearchResult.asp?$qstring" HTTP::respond 301 Location "http://[HTTP::host]/" } }
- Fotios_30046
Nimbostratus
Gents,when HTTP_REQUEST { if {[HTTP::path] == "/common/search/SearchCombined.asp"} { set CategoryID1 [findstr [HTTP::query] "category=" 9 "&"] if {$CategoryID1 != ""} { set CategoryID2 [findclass $CategoryID1 $::CategoryIDs " "] } if {$CategoryID2 != ""} { HTTP::respond 301 Location "http://[HTTP::host]/common/search/SearchResult.asp?CategoryID=$CategoryID2" } } }
- Great, glad to help... Feel free to post again if any other issues come up.
- In looking at your code, I see a couple possible of issues that may come up. Mainly with your "if {$CategorID2 != ""}" line. You only set that variable if the CategoryID1 value is found in the query string. What happens if it's not there? CategoryID2 will not get set and you will have a runtime error when trying to evaluate the value against the empty string. Also, if the user is on a keepalive connection, the variables you are setting are session variables so they will be around for the entire session and CategoryID2 could be set from a previous request and CategoryID1 isn't set from the current request.
when HTTP_REQUEST { if {[HTTP::path] == "/common/search/SearchCombined.asp"} { set CategoryID1 [findstr [HTTP::query] "category=" 9 "&"] if {$CategoryID1 != ""} { set CategoryID2 [findclass $CategoryID1 $::CategoryIDs " "] if {$CategoryID2 != ""} { HTTP::respond 301 Location "http://[HTTP::host]/common/search/SearchResult.asp?CategoryID=$CategoryID2" } } } }
- Fotios_30046
Nimbostratus
Joe, - Great, glad to help... Please let us know if you have any other issues in the future as we'd be glad to do our best to help you out.
- Fotios_30046
Nimbostratus
During the iRule creation, a specific match list was given to me by our product management team. This list was very simple, that it had single text on one side and numerical matches on the left. Since I'm logging all variables within the iRule, I noticed that special characters are also possible as variables.
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