cancel
Showing results for 
Search instead for 
Did you mean: 

HowTo TS-Rule with multiple Conditions in one Rule ?

SOLVED
Highlighted
Occasional Contributor

HowTo TS-Rule with multiple Conditions in one Rule ?

Hi @ all,

once again a question about TrafficScript ...

I want to define a rule with multiple terms but it should only be 1 rule ...

Here´s the situation:

My url is http://test.com,

my Url-Path is "path1",

my selected Pool is "pool-1"

the difficulty here is, that the Backend-Server (pool-1) don´t listen at "path1" , only at "path2", so I´ve to rewrite "path1" in "path2"

Here´s my rule, unfortunately it doesn´t work.


$path = http.getpath();



if( http.getheader( "host" ) == "http://test.com"


        && $path == "/path1 " ){



        $path = string.regexsub( $path, "path1 ", "path2" );


        http.setpath( $path );



   pool.use( "pool-1" );


}





At the end it should be like this:

I call "http://test.com/path1" and the TrafficManager routed it to "pool1" and changed "path1" into "path2".

Can somebody help me here or have an idea where´s my mistake?

Regards,

Michael

5 REPLIES
Occasional Contributor

Re: HowTo TS-Rule with multiple Conditions in one Rule ?

Hi Michael,

I've noticed a white space in your script inside regexsub statement.

Is it an error in copy/paste?

Stefano

Occasional Contributor

Re: HowTo TS-Rule with multiple Conditions in one Rule ?

Hi Stefano,

yes, thia was an copy/paste error ... here´s the content again:

$path = http.getpath();

if( http.getheader( "host" ) == "http://test.com"

        && $path == "/path1 " ){

        $path = string.regexsub( $path, "path1", "path2" );

        http.setpath( $path );

   pool.use( "pool-1" );

}

Occasional Contributor

Re: HowTo TS-Rule with multiple Conditions in one Rule ?

Ok, have you tried to check what is returned by "getPath"?

You can also try to substitute "$path == "/path1 "" with string.startWithI($path, "/path1")

Now I've got to go.

Bye

Stefano

Contributor

Re: HowTo TS-Rule with multiple Conditions in one Rule ?

Hi Michael,

I would have written your rule like this:

  1. $path = http.getPath(); 
  2.   if( http.getHostHeader() == "test.com" && string.startsWith($path, "/path1") ){ 
  3.         $path = string.replace( $path, "/path1", "/path2"); 
  4.         http.setPath( $path); 
  5.    pool.use( "pool-1"); 

The Host header does not contain the URL scheme, and you have a trailing space character at the end of your "/path1 " string in the condition too.

Cheers

Occasional Contributor

Re: HowTo TS-Rule with multiple Conditions in one Rule ?

Hello Sameh,

thanks fior you answer.

I´ll check this and come back to you.

Regards