vADC Forum

Reply
krm
Occasional Contributor
Posts: 5
Registered: ‎05-12-2014

How to easily rewrite URL path needed by pool servers

I have looked throughout Stingray documentation and have not found this common scenario.  We currently implement the following rule structure in Apache/mod_proxy:

# BEGIN #######################################################################

<Proxy balancer://foo-cluster>
  BalancerMember http://apps-01.juniper.net:8080 loadfactor=1 keepalive=On
  BalancerMember http://apps-02.juniper.net:8080 loadfactor=1 keepalive=On
  BalancerMember http://apps-03.juniper.net:8080 loadfactor=1 keepalive=On
  ProxySet lbmethod=byrequests
  ProxySet timeout=60
</Proxy>

# current deployment path

ProxyPass /foo              balancer://foo-cluster/foo

# legacy deployment location !! CANT FIND SOLUTION IN STINGRAY

ProxyPassMatch /bar/foo(.*) balancer://foo-cluster/foo$1

# hosting same service from /foobar !! CANT FIND SOLUTION IN STINGRAY

ProxyPassMatch /foobar balancer://foo-cluster/foo

ProxyPassReverse / http://apps-01.juniper.net:8080/
ProxyPassReverse / http://apps-02.juniper.net:8080/
ProxyPassReverse / http://apps-03.juniper.net:8080/

# END #######################################################################

So when a user enters any one of these below, the user should experience the same page while not causing any browser redirects.  The external URL interface should remain unchanged:

http://www.example.com/foo

http://www.example.com/bar/foo

http://www.example.com/foobar

Please help us solve the correct syntax in traffic script to enable this.

Contributor
Posts: 40
Registered: ‎03-26-2013

Re: How to easily rewrite URL path needed by pool servers

I don't know mod_proxy so I am not sure what you are trying to achieve, but it looks like you just need to rewrite the URI?

Then you should use http.getPath() / http.setPath() combined with string replacement functions. When used in a TS request rule this will rewrite the URI before passing the request to the backend.

You don't seem to need regexp here, so this should help, and if it is wrong, at least it should get you closer to the solution

$path = http.getPath();

if (string.startsWith($path, "/foobar")) {

  $path = string.replace($path, "/foobar", "/foo");

}

if (string.startsWith($path, "/bar/foo")) {

  $path = string.replace($path, "/bar", "");

}

http.setPath($path);

krm
Occasional Contributor
Posts: 5
Registered: ‎05-12-2014

Re: How to easily rewrite URL path needed by pool servers

Thanks for replying, but we did try the exact solution you wrote, but the solution doesn't quite do what we expected.

Once the setPath() is called, the client browser's URL location is also set to the new path.  This is not the behavior we need.  We need to original path to stay visible in the URL location while the back end requests are routed to the rewritten location.

New Contributor
Posts: 3
Registered: ‎11-29-2012

Re: How to easily rewrite URL path needed by pool servers

$path = http.getPath();

if (string.startsWith($path, "/foobar")) {

  pool.use("xxxx");

}

if (string.startsWith($path, "/bar/foo")) {

  pool.use("xxxx");

}

Is this worked?

Contributor
Posts: 40
Registered: ‎03-26-2013

Re: How to easily rewrite URL path needed by pool servers

http.setPath() only rewrites the first line of the request before it is sent to the backends. If the browser is aware of this, it means the backend does something more, for instance sending HTTP 301/302 redirects.

krm
Occasional Contributor
Posts: 5
Registered: ‎05-12-2014

Re: How to easily rewrite URL path needed by pool servers

I'm pretty sure its not doing any redirects as our test case was just a simple php page designed to output header and environment variables.  So maybe you can help clarify.  The setPath() function does not affect the response content in any way?  If setPath() is used in the request rule, would I need to construct a response rule to intercept the content and change the Location header or any other headers?   Our applications are designed to use either relative paths or absolute paths without any host.domain in the URLs.

Contributor
Posts: 40
Registered: ‎03-26-2013

Re: How to easily rewrite URL path needed by pool servers

No, setPath() only affects the request.

That is why you might have to do the inverse search and replace on the response, headers or body if your application needs it.

Join the Community

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