vADC Forum

Reply
New Contributor
Posts: 2
Registered: ‎10-14-2013
Accepted Solution

Simple Redirect script

Hi Folks,

First timer on splash and writing my own traffic script infact so go easy on me, this will be very much sucking eggs for most people i guess.

We have a requirement to point any traffic coming in to the URL http://www.suckeggs.com/scotland to be pointed to a different internal server whilst all other traffic for http://www.suckeggs.com and subsections of that site will remain pointing to the same backend pool.

Thanks

Rob

Frequent Contributor
Posts: 321
Registered: ‎11-29-2012

Re: Simple Redirect script

Hi Rob,

This is really easy to do, either using RuleBuilder or TrafficScript.  RuleBuilder is a simple 'if-condition-then-action' GUI front-end to TrafficScript.

Before you write your rule:

  • Ensure you have configured a 'Pool' for your most common web traffic.  Set this to be the 'default pool' for your virtual server.  All traffic will be handled by that pool unless a rule intercepts the traffic and selects a different pool.
  • Create a pool for the /scotland traffic.  This pool should contain the server(s) you want to use to handle that traffic.  Let's call that pool 'scotland'

Then you need to create a rule using RuleBuilder, or write a rule using TrafficScript, to intercept the /scotland traffic and divert it to the scotland pool:

RuleBuilder


IF HTTP Path is '/scotland'


  - AND -


IF HTTP Host Header is 'www.suckeggs.com'


- THEN -


Use Pool 'scotland'


TrafficScript


if( http.getHostHeader() == "www.suckeggs.com" ) {


  if( http.getPath() == "/scotland" ) {


    pool.use( "scotland" );


  }


}


Hope that this helps

Owen

New Contributor
Posts: 2
Registered: ‎10-14-2013

Re: Simple Redirect script

Hi Owen,

Thanks for this helpful response. Unfortunately i have only just around to implementing this as the site was note ready until late this afternoon.

I have created the required groups and set up the rule using an edited version of your trafficscript (with the actual URL and HTTP Path) and whilst this no longer returns a 404 I do not get the full site I am expecting, but rather a cut down, low res version of the site.

EDIT: it looks like the HTTP Path "/scotland" is being passed to the second pool, and because this doesn't exist i receive a different page. Am i able to remove this from the URL without the end user being aware?

Thanks in advance all.

Rob

Contributor
Posts: 58
Registered: ‎11-29-2012

Re: Re: Simple Redirect script

Where "unicorn" replaces the path portion of the request URL.


if( http.getHostHeader() == "www.suckeggs.com" ) {


  if( http.getPath() == "/scotland" ) {


    http.setpath( "/unicorn" );


    pool.use( "scotland" );


  }


}



Frequent Contributor
Posts: 321
Registered: ‎11-29-2012

Re: Re: Simple Redirect script

Hi Rob,

As David Nahas showed, you may use http.setPath() to change the URL in the request.  Stingray will then send the modified request to the selected server; the remote client does not see the changed request.

The other common method is to use http.redirect(); this sends a 302 Redirect response back to the client telling it to 'try this URL'.  The redirect is visible to the end user.

One possible gotcha when using http.setPath() is that embedded relative links or redirects from the content may not work, so images, stylesheets and the rest may not be displayed (this may be why you see a cut-down, low-res version of the site).  For example, if you modify a URL from /scotland/index.html to /scotland.html, then the web client will look for resources relative to /scotland/, although the content was served from /.  Use the developer tools in your web browser to see if your client is requesting resources that return an unexpected 404 Not Found.

regards

Owen

Join the Community

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