Creating Extensionless links

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.

Sometimes you may want to support extension less links, either to hide extensions from end users or to make URLs easy to remember.

Example 1: add .php extension to all requests

Apache rewrite:

RewriteRule ^/?([a-z]+)$ $1.php [L]

AppExpert rewrite:

Add rewrite action act1 insert_after 'HTTP.REQ.URL' '<span class="code-quote">".php"</span>'
Add rewrite policy pol1 'HTTP.REQ.URL.PATH.REGEX_MATCH(re#^/([a-z]+)$#)' act1
Bind rewrite global pol1 100

Example 2: if we have a mixture of both .html and .php files, the following can be used

Apache rewrite:

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^/?([a-zA-Z0-9]+)$ $1.php [L]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^/?([a-zA-Z0-9]+)$ $1.html [L]

AppExpert rewrite:
Here HTTPCallout would be used, script file_check.cgi hosted on is used to check wether provided argument is avalid file name or not.

add HTTPCallout Call_html
add HTTPCallout Call_php
set policy httpCallout Call_html -IPAddress -port 80 -hostExpr '<span class="code-quote">""</span>' -returnType BOOL -ResultExpr 'HTTP.RES.BODY(100).CONTAINS(<span class="code-quote">"True"</span>)'  -urlStemExpr '<span class="code-quote">"/cgi-bin/file_check.cgi"</span>'   -parameters query=http.req.url+<span class="code-quote">".html"</span>
set policy httpCallout Call_php -IPAddress -port 80 -hostExpr '<span class="code-quote">""</span>' -returnType BOOL -ResultExpr 'HTTP.RES.BODY(100).CONTAINS(<span class="code-quote">"True"</span>)'  -urlStemExpr '<span class="code-quote">"/cgi-bin/file_check.cgi"</span>' -parameters query=http.req.url+<span class="code-quote">".php"</span>
Add patset pat1
Bind patset pat1 .html
Bind patset pat1 .php
Bind patset pat1 .asp
Bind patset pat1 .cgi
Add rewrite  action act1 insert_after 'HTTP.REQ.URL.PATH'  '<span class="code-quote">".html"</span>'
Add rewrite  action act2 insert_after <span class="code-quote">"HTTP.REQ.URL.PATH"</span>  '<span class="code-quote">".php"</span>'
Add rewrite policy pol1 '!HTTP.REQ.URL.CONTAINS_ANY(<span class="code-quote">"pat1"</span>) &amp;&amp; SYS.HTTP_CALLOUT(Call_html)' act1
Add rewrite policy pol2 '!HTTP.REQ.URL.CONTAINS_ANY(<span class="code-quote">"pat1"</span>) &amp;&amp; SYS.HTTP_CALLOUT(Call_php)' act2
Bind rewrite global pol1 100 END
Bind rewrite global pol2 101 END

Tap into the power of AppExpert!