Redirecting a URI to a new format

The Citrix NetScaler can be placed in front of a webserver farm that is running Apache. The same re-write rules that run on Apache, can be implemented on the Citrix NetScaler.

Let’s say, for example, that you’ve got a set of working URLs that look like this: /index.php?id=nnnn. However, you’d really like to change them to /nnnn and make sure search engines update their indexes to the new URI format. First, you’d have to redirect the old URIs to the new ones so that search engines update their indexes, but you still have to rewrite the new URI back to the old one so that the index.php script would run.

Example: The trick here is to place into the query string a marker code that will not be seen by visitors. We redirect from the old link to the new format only if the “marker” is not present in the query string. Then we rewrite the new format link back to the old format, and add a marker to the query string.

Apache rewrite:

RewriteCond %{QUERY_STRING} !marker
RewriteCond %{QUERY_STRING} id=([-a-zA-Z0-9_+]+)
RewriteRule ^/?index\.php$ %1? [R,L]
RewriteRule ^/?([-a-zA-Z0-9_+]+)$  index.php?marker&id=$1 [L]

AppExpert rewrite:

Add responder action act_redirect redirect 'HTTP.REQ.URL.PATH.BEFORE_STR(<span class="code-quote">"index.php"</span>)+HTTP.REQ.URL.QUERY.VALUE(<span class="code-quote">"id"</span>)' -bypassSafetyCheck yes
Add responder policy pol_redirect '!HTTP.REQ.URL.QUERY.CONTAINS(<span class="code-quote">"marker"</span>)&amp;&amp; HTTP.REQ.URL.QUERY.VALUE(<span class="code-quote">"id"</span>).REGEX_MATCH(re/[-a-zA-Z0-9_+]+/) &amp;&amp; HTTP.REQ.URL.PATH.CONTAINS(<span class="code-quote">"index.php"</span>)' act_redirect
Bind responder  global pol_redirect 100 END
Add rewrite action act1 replace 'HTTP.REQ.URL.PATH.SUFFIX(\'/\',0)' '<span class="code-quote">"index.phpmarker&amp;id="</span>+HTTP.REQ.URL.PATH.SUFFIX(\'/\',0)' -bypassSafetyCheck yes
Add rewrite policy pol1 '!HTTP.REQ.URL.QUERY.CONTAINS(<span class="code-quote">"marker"</span>)'  act1
Bind rewrite global pol1 100 END

Tap into the power of AppExpert!