Appendix C: Scripts : Examples : Select content routes based on URI string matches
Select content routes based on URI string matches
The content routing feature has rules that match HTTP requests to content routes based on a Boolean AND combination of match conditions. If you want to select routes based on a Boolean OR, you can configure multiple rules. The content routing rules table is consulted from top to bottom until one matches.
In some cases, it might be simpler to get the results you want using a script. In the following example, each rule selects content routes based on OR match conditions.
-- Content routing example
when RULE_INIT {
debug("get header init 1\n")
uri = HTTP:uri_get()
if uri:find("sports") or uri:find("news") or uri:find("government") then
debug("uri %s matches sports|news|government\n", uri);
elseif uri:find("finance") or uri:find("technology") or uri:find("shopping") then
debug("uri %s matches finance|technology|shopping\n", uri);
elseif uri:find("game") or uri:find("bbs") or uri:find("testing") then
debug("uri %s matches game|bbs|testing\n", uri);
elseif uri:find("billing") or uri:find("travel") or uri:find("weibo") then
debug("uri %s matches billing|travel|weibo\n", uri);
debug("no matches for uri: %s \n", uri);
To use a script for content routing:
1. Create the content route configuration objects. In the example above, sp2, sp3, sp4, and sp4 are the names of the content route configuration objects. You do not need to configure matching conditions for the content routes, however, because the script does the content matching.
2. Create a script that matches content to the content route configuration objects, as shown above. Create a configuration object for the script.
3. In the virtual server configuration:
Enable content routing and select the content route configuration objects.
Select the script.