vADC Forum

Occasional Contributor
Posts: 15
Registered: ‎11-29-2012
Accepted Solution

How to redirect Domains/Url with Trafficscript

Hi @ all,

I´ve once again a short question ...

I try to redirect all of our reserved Domains to our Main-Domain and I´ll do this with TS.

It should be regardless if the Domains are called with 'www' or without 'www' and if something is behind the '/'  or not ...

an example:

Domain "" and "" (also* and* )

should be redirected to ""

Here´s my TS-Rule, at the moment every Domain has it´s own line (without and with 'www' )

but how can I realize as short as possible (because we have many of them), that this Domains when called with "www" will also be redirected ?

$headerhost = http.getheader( "host" );

if( $headerhost == ""

     || $headerhost ==

     || $headerhost == "”

     || $headerhost == ""

|| $headerhost == ""

|| $headerhost == ""

|| $headerhost == ""

|| $headerhost ==


  http.changeSite( ""/ );  }


The Rule have to be with Syntax "$headerhost == " instead of "$headerhost contains " because some of the Domainnames are used as a Subdomain ...and these shouldn´t be redirected of course ...

Perhaps somebody have a hint for me?



Occasional Contributor
Posts: 12
Registered: ‎12-13-2013

Re: How to redirect Domains/Url with Trafficscript

We have a similar situation.  Rather than use a big list of conditions chained together with II we use a resource file.  It's syntactically prettier, but also you could update the list without having to rewrite the TrafficScript.  We update ours with the REST API.  Here's what you might try (NOT TESTED!):

# Make a resource file called domains.txt and put it in your catalogs > extra files

# > miscellaneous files.  Each line in the text file has a domain name that you

# want to match to redirect.

$resource = 'domains.txt';

# make sure the file is present before you attempt to parse it.

if(! (resource.exists($resource))){

  # uncomment this line if you want to log when it's missing.

  # log.warn("Resource file " . $resource . " not found!");



$hostHeader = http.getHostHeader();

$domains = resource.getLines($resource);

foreach ($line in $domains){

  $domain = $string.trim($line);

  if ($hostHeader == $domain){




Now, you could use a string.regexmatch to check a domain entry with the host header, but be careful!  You may accidentally match domains too broadly.

Join the Community

Get quick and easy access to valuable resource designed to help you manage your Brocade Network.