Appendix C Tutorial Examples of Advanced Policies for Rewrite 247
Redirecting a Query
This example describes how to create a Rewrite action and Rewrite policy that
redirects a query to the proper URL. The example assumes that the request
contains a Host header set to www.example.com and a GET method with the
string /query.cgi?server=5. The redirect extracts the domain name from the
host header and the number from the query string, and redirects the user’s query
to the server Web5.example.com, where the rest of the user’s query is
processed.
Note: Although the following commands appears on multiple lines, you should
enter them on a single line without line breaks.
To redirect a query to the appropriate URL using the command line
1. To create a Rewrite action named act_redirect_query that replaces
the HTTP server hostname with the internal server name, type:
add rewrite action act_redirect_query REPLACE
q#http.req.header("Host").before_str(".example.com")' '"Web" +
http.req.url.query.value("server")#
2. To create a Rewrite policy named pol_redirect_query, type the
following commands at the NetScaler command prompt.. This policy
detects connections, to the Web server, that contain a query string. Do not
apply this policy to connections that do not contain a query string:
add rewrite policy pol_redirect_query
q#http.req.header("Host").eq("www.example.com") &&
http.req.url.contains("?")' act_redirect_query#
3. Bind your new policy globally.
Since this Rewrite policy is highly specific and should be run before any
other Rewrite policies, it is advisable to assign it a high priority. If you
assign it a priority of 1, it will be evaluated first.
Redirecting HTTP to HTTPS
This example describes how to rewrite Web server responses to find all URLs that
begin with the string “http” and replace that string with “https”. You can use this
to avoid having to update Web pages after moving a server from HTTP to
HTTPS.