Failed URL Redirect



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.

In case the current url is not valid & the request needs to be redirected to another web server, the following steps could be taken.

Example : We will check weather the request filename exists on the server or not, in case it fails then redirection is done to another webserver (for example, webServerB.com). In the case of AppExpert, HTTPCallout is used to check the presence of the file on the server by running a script file_check.cgi on the server. The returned value from HTTPCallout is used to validate the policy.

The Script file_check.cgi takes the url as the argument, checks for its presence on the server & returns True or False accordingly.

Apache rewrite:

RewriteCond   /your/docroot/%{REQUEST_FILENAME} !-f
RewriteRule   ^(.+)      http:<span class="code-comment">//webserverB.com/$1 [R]</span>



AppExpert rewrite: (There are two ways to do this)

“Solution 1”
add HTTPCallout Call

set policy httpCallout Call -IPAddress 10.102.59.101 -port 80 -hostExpr '<span class="code-quote">"10.102.59.101"</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.path -headers Name(<span class="code-quote">"ddd"</span>)

add responder action act1 redirect '<span class="code-quote">"http:<span class="code-comment">//webserverB.com"</span>+HTTP.REQ.URL' -bypassSafetyCheck yes
</span>
add responder policy pol1 '!HTTP.REQ.HEADER(<span class="code-quote">"Name"</span>).EXISTS  &amp;&amp;  !SYS.HTTP_CALLOUT(call)' act1

bind responder global pol1 100
“Solution 2:”
add HTTPCallout Call

set policy httpCallout Call -IPAddress 10.102.59.101 -port 80 -hostExpr '<span class="code-quote">"10.102.59.101"</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.path -headers Name(<span class="code-quote">"ddd"</span>)

add responder  action act1 respondwith  '<span class="code-quote">"HTTP/1.1 302 Moved Temporarily\r\nLocation: http:<span class="code-comment">//webserverB.com"</span>+HTTP.REQ.URL+<span class="code-quote">"\r\n\r\nHTTPCallout Used"</span>' -bypassSafetyCheck yes
</span>
add responder policy pol1 '!HTTP.REQ.HEADER(<span class="code-quote">"Name"</span>).EXISTS  &amp;&amp;  !SYS.HTTP_CALLOUT(call)' act1

bind responder global pol1 100



Tap into the power of AppExpert!