This article contains information about how to advanced Policy Infrastructure (PI) expressions as an alternative to URL transformation.
The URL Transformation feature is one method that you can use to modify inbound or outbound URL paths for various reasons such as Search Engine Optimization (SEO). The main limitation of this type of solution is that you have to create a 1:1 mapping of all the URLs you need to transform. URL Transformation is a suitable solution when you have irregular patterns, but the most common use case for URL Transformation is SEO use case which is more often replacing the query string parameters consumed by Web application framework with something more human readable.
Example 1
www.example.com/1/bob-895.html > www.example.com/895/prod.asp?id=1 www.example.com/2/bob-170.html > www.example.com/170/prod.asp?id=2
Example 2
www.example.com/1/bob-895.html > www.example.com/media/prod.asp?id=895
When you are transforming the URL path and queries to flat structure that are made up of the same elements, you do not need to use complex regular expression policies. You can define built-in Advanced PI policy expressions which accommodate this scenario in a single policy.
For the second example you can use the String Maps feature to have a hybrid approach and include a mechanism outside policy definition to add and update string elements that you must replace in the URL paths.
To accomplish this procedure, you must enable the Rewrite feature on the NetScaler appliance. The Rewrite feature is available on all editions of a NetScaler appliance. The following screen shot is from the Graphical User Interface (GUI) of the appliance:
Run the following commands to enable the rewrite feature from the command line interface:
Enable ns feature rewrite
To use advanced Policy Infrastructure (PI) expressions as an alternative to URL transformation, complete the following information:
The following screen shots describes how to use built-in PI expressions to reference entities in the request URL as replacement strings in the resultant rewrite expression:
Run the following commands to setup the preceding configuration:
add rewrite action act1 replace HTTP.REQ.URL '"/"+HTTP.REQ.URL.PATH.GET_REVERSE(0).AFTER_STR("-").BEFORE_STR(".html")+"/prod.asp\?id="+HTTP.REQ.URL.PATH.GET(1)' -byPassSafetyCheck YES
add rewrite policy pol1 true act1
If you combine the preceding PI policies with the String Map feature as a replacement index, you can accommodate the second example:
Run the following commands to setup the preceding configuration:
add policy stringmap string_map_1
bind policy stringmap string_map_1 1 media
add rewrite action act2 replace "HTTP.REQ.URL.PATH.GET(1)" "HTTP.REQ.URL.PATH.GET(1).SET_TEXT_MODE(IGNORECASE).MAP_STRING(\"string_map_1\")" -bypassSafetyCheck YES
add rewrite policy pol2 "HTTP.REQ.URL.PATH.GET(1).IS_STRINGMAP_KEY(\"string_map_1\")" act2
Bind these policies to the appropriate location such as the virtual server defined for the Web application or at a global level:
Run the following commands to setup the preceding configuration:
bind lb vserver lb_web_app1 -policyName pol1 -priority 100 -gotoPriorityExpression END -type REQUEST
bind lb vserver lb_web_app1 -policyName pol2 -priority 110 -gotoPriorityExpression END -type REQUEST
Example 1
Example 2