Example 6: Migrating Apache Rewrite Module Rules

Example Inc., is currently using the Apache rewrite module to process search requests sent to its Web servers and redirect those requests to the appropriate server on the basis of information in the request URL. Example Inc. wants to simplify its setup by migrating these rules onto the NetScaler platform.

Several Apache rewrite rules that Example currently uses are shown below. These rules redirect search requests to a special results page if they do not have a SiteID string or if they have a SiteID string equal to zero (0), or to the standard results page if these conditions do not apply.

The following are the current Apache rewrite rules:

  • RewriteCond %{REQUEST_FILENAME} ^/search$ [NC]
  • RewriteCond %{QUERY_STRING} !SiteId= [OR]
  • RewriteCond %{QUERY_STRING} SiteId=0
  • RewriteCond %{QUERY_STRING} CallName=DisplayResults [NC]
  • RewriteRule ^.*$ /results2.html [P,L]
  • RewriteCond %{REQUEST_FILENAME} ^/search$ [NC]
  • RewriteCond %{QUERY_STRING} CallName=DisplayResults [NC]
  • <RewriteRule ^.*$ /results.html [P,L]

To implement these Apache rewrite rules on the NetScaler, you would create rewrite actions with the values in the following tables.

Action Name Type of Rewrite Action Expression to choose target reference String expression for replacement text
Action-Rewrite-Display_Results_NulSiteID REPLACE HTTP.REQ.URL “/results2.html”
Action-Rewrite-Display_Results REPLACE HTTP.REQ.URL “/results2.html”

You would then create rewrite policies with the values as shown in the tables below.

Policy Name Action Name Undefined Action Expression        
Policy-Rewrite-Display_Results_NulSiteID Action-Rewrite-Display_Results_NulSiteID NOREWRITE HTTP.REQ.URL.PATH.SET_TEXT_MODE(IGNORECASE).EQ(“/search”) && (!HTTP.REQ.URL.QUERY.CONTAINS(“SiteId=”)   HTTP.REQ.URL.QUERY.CONTAINS(“SiteId=0”)   HTTP.REQ.URL.QUERY.SET_TEXT_MODE(IGNORECASE).CONTAINS(“CallName=DisplayResults”))
Policy-Rewrite-Display_Results Action-Rewrite-Display_Results NOREWRITE HTTP.REQ.URL.PATH.SET_TEXT_MODE(IGNORECASE).EQ(“/search”)   HTTP.REQ.URL.QUERY.SET_TEXT_MODE(IGNORECASE).CONTAINS(“CallName=DisplayResults”))    

Finally, you would bind the rewrite policies, assigning the first a priority of 600 and the second a priority of 700, and then set the goto expression to NEXT for both bindings.

The NetScaler now handles these search requests exactly as the Web server did before the Apache rewrite module rules were migrated.

Example 6: Migrating Apache Rewrite Module Rules

In this article