Canonical Hostnames



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.

The goal of the following rule is to force the use of a particular hostname, in preference to other hostnames which may be used to reach the same site. For example, if you wish to force the use of www.example.com instead of example.com, you might use a variant of the following rules.

Example : changing example.com to www.example.com

Apache rewrite:

“Sites running other than port 80”
RewriteCond %{HTTP_HOST}   !^www.example.com
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^/(.*)         http:<span class="code-comment">//www.example.com:%{SERVER_PORT}/$1 [L,R]</span>
“Sites running port 80”
RewriteCond %{HTTP_HOST}   !^www.example.com
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/(.*)         http:<span class="code-comment">//www.example.com/$1 [L,R]</span>



AppExpert rewrite:

“Sites running other than port 80”
add responder action act1 redirect '<span class="code-quote">"http:<span class="code-comment">//www.example.com:"</span>+CLIENT.TCP.DSTPORT+HTTP.REQ.URL' -bypassSafetyCheck yes
</span>add responder policy pol1 '!HTTP.REQ.HOSTNAME.CONTAINS(<span class="code-quote">"www.example.com"</span>)&amp;&amp;!HTTP.REQ.HOSTNAME.EQ(<span class="code-quote">"")&amp;&amp;!HTTP.REQ.HOSTNAME.PORT.EQ(80)&amp;&amp;HTTP.REQ.HOSTNAME.CONTAINS("</span>example.com")' act1
bind responder global pol1 100 END
“Sites running port 80”
add responder action act1 redirect '<span class="code-quote">"http:<span class="code-comment">//www.example.com"</span>+HTTP.REQ.URL' -bypassSafetyCheck yes
</span>add responder policy pol1  '!HTTP.REQ.HOSTNAME.CONTAINS(<span class="code-quote">"www.example.com"</span>)&amp;&amp;!HTTP.REQ.HOSTNAME.EQ(<span class="code-quote">"")&amp;&amp;HTTP.REQ.HOSTNAME.PORT.EQ(80)&amp;&amp;HTTP.REQ.HOSTNAME.CONTAINS("</span>example.com")' act1
bind responder global  pol1 100 END



Tap into the power of AppExpert!